2012-02-10 72 views
1

嘿,我是新的iOS开发,在我的应用程序,我想从文档文件夹中获取视频文件到表视图。但是这些文件在表格视图中没有得到加载。所以请告诉我,我在哪里犯了一个错误..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

你忘了设置:

tblView.datasource = self; 
+0

仍然没有工作... – 2012-02-10 08:27:19

+0

日Thnx 4乌拉圭回合的帮助.. – 2012-02-10 08:27:51

+0

任何别的东西,即时通讯丢失或出错... – 2012-02-10 09:57:16