Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Display Thumbnail

Hi I am new to iPhone app development. I want help, i want to know how do i display an video file (name and thumbnail) in table view..I am fetching video file from Document directory but only name of video appear and not thumbnail..Here is code that i have used for fetching video file..


#import \"VideoListViewController.h\"
#import \"ThirdViewController.h\"

@implementation VideoListViewController
@synthesize thirdViewController;
@synthesize videoList, videoListNames;
@synthesize tblView;

- (id)initWithStyle:(UITableViewStyle)style
{
self = [self initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

-(void) dealloc{
[super dealloc];
[videoListNames release];
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}

- (void)viewDidLoad
{

[super viewDidLoad];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@\"Edit\" style:UIBarButtonItemStyleBordered target:self action:@selector(EditTable:)];
[self.navigationItem setRightBarButtonItem:addButton];

self.tblView.delegate = self;
self.tblView.dataSource = self;
NSFileManager *filemgr = [NSFileManager defaultManager];
NSString *docDirPath = NSHomeDirectory();
docDirPath = [docDirPath stringByAppendingPathComponent:@\"Documents\"];
NSArray *filelist = [filemgr contentsOfDirectoryAtPath:docDirPath error:NULL];
NSLog(@\"filelist = %@\",filelist);
int count = [filelist count];
NSString *currentFileName;
videoListNames = [[NSMutableArray alloc] initWithCapacity:2];
for (int j = 0; j < count; j++)
{
currentFileName = (NSString *)[filelist objectAtIndex:j];
if ([[currentFileName pathExtension] isEqualToString:@\" \"])
{
NSLog(@\"currentFileName = %@\",currentFileName);
//[videoListNames addObject:currentFileName];
}
[videoListNames addObject:currentFileName];
}
NSLog(@\"Count >>>> %d\",[videoListNames count]);

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[tblView reloadData];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

int count = [videoListNames count];
if(self.editing) count++;
return count;

// Return the number of rows in the section.
/*
NSLog(@\"Number of Items in array %d\", [videoListNames count]);
return [videoListNames count];
*/
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *CellIdentifier = @\"Cell\";

UITableViewCell *cell = [tblView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

for(UIView *view in cell.contentView.subviews){
if ([view isKindOfClass:[UIView class]]) {
[view removeFromSuperview];
}
}
//Configure the cell...

if(indexPath.row %2 == 0)
{
cell.backgroundView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@\"Stript1.png\"]];
}
else cell.backgroundView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@\"Stript2.png\"]];

int count = 0;
if(self.editing && indexPath.row != 0)
count = 1;
NSLog([NSString stringWithFormat:@\"%i,%i\",indexPath.row,(indexPath.row-count)]);

// Set up the cell...
if(indexPath.row == ([videoListNames count]) && self.editing)
{
//cell.textLabel.text = @\"ADD\";
return cell;
}

cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor whiteColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.text = (NSString *)[videoListNames objectAtIndex:indexPath.row];
NSLog(@\"cell text = %@\",cell.textLabel.text);
// Configure the cell.
return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70.0f;
}

- (IBAction)DeleteButtonAction:(id)sender
{
[videoListNames removeLastObject];
[tblView reloadData];
}

- (IBAction) EditTable:(id)sender
{
if(self.editing)
{
[super setEditing:NO animated:NO];
[tblView setEditing:NO animated:NO];
[tblView reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@\"Edit\"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else
{
[super setEditing:YES animated:YES];
[tblView setEditing:YES animated:YES];
[tblView reloadData];
[self.navigationItem.leftBarButtonItem setTitle:@\"Done\"];
[self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}

// The editing style for a row is the kind of button displayed to the left of the cell when in editing mode.
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
// No editing style if not editing or the index path is nil.
if (self.editing == NO || !indexPath) return UITableViewCellEditingStyleNone;
// Determine the editing style based on whether the cell is a placeholder for adding content or already
// existing content. Existing content can be deleted.
if (self.editing && indexPath.row == ([videoListNames count]))
{
return UITableViewCellEditingStyleInsert;
} else
{
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}

// Update the data model according to edit actions delete or insert.
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{

if (editingStyle == UITableViewCellEditingStyleDelete)
{
[videoListNames removeObjectAtIndex:indexPath.row];
[tblView reloadData];
} else if (editingStyle == UITableViewCellEditingStyleInsert)
{
[videoListNames insertObject:@\"Tutorial\" atIndex:[videoListNames count]];
[tblView reloadData];
}
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
// Process the row move. This means updating the data model to correct the item indices.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
NSString *item = [[videoListNames objectAtIndex:fromIndexPath.row] retain];
[videoListNames removeObject:item];
[videoListNames insertObject:item atIndex:toIndexPath.row];
[item release];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ThirdViewController *thirdViewController =[self.storyboard instantiateViewControllerWithIdentifier:@\"thirdViewController\"];
[self.navigationController pushViewController:thirdViewController animated:YES];
thirdViewController.title = [[[self tableView:tblView cellForRowAtIndexPath:indexPath] textLabel]text];
thirdViewController.label.text = [[[self tableView:tblView cellForRowAtIndexPath:indexPath] textLabel]text];

}
@end
Sign In or Register to comment.