2012-02-10 71 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