Hey i am new to iOS development, in my app i want to fetch video file from document folder to table view. But the files are not getting load in table view. so please tell me where am i making a mistake..
- (void)viewDidLoad
{
[super viewDidLoad];
tblView.delegate = 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 array];
for (int j = 0; j<count; j++)
{
currentFileName = (NSString *)[filelist objectAtIndex:j];
if ([[currentFileName pathExtension] isEqualToString:@".avi"])
{
NSLog(@"currentFileName = %@",currentFileName);
[videoListNames addObject:currentFileName];
}
}
[tblView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return videoListNames.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
//TRY TO REMOVE ALL CONTENT
for(UIView *view in cell.contentView.subviews){
if ([view isKindOfClass:[UIView class]]) {
[view removeFromSuperview];
}
}
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//cell.backgroundView.frame =
cell.textLabel.text = (NSString *)[videoListNames objectAtIndex:indexPath.row];
NSLog(@"cell text = %@",cell.textLabel.text);
// Configure the cell.
return cell;
}
have you forgotten to set:
tblView.datasource = self;