IOS - 表格视图未加载

时间:2012-02-10 05:25:57

标签: ios4

嘿,我是iOS开发的新手,在我的应用程序中,我想将文件夹中的视频文件提取到表格视图。但是文件在表视图中没有加载。所以请告诉我我在哪里弄错了..

- (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;

}

1 个答案:

答案 0 :(得分:1)

你忘了设置:

tblView.datasource = self;