【发布时间】:2010-12-16 22:53:14
【问题描述】:
我试图在 TableView 中列出 Ringtones 目录的内容,但是,我只获取所有单元格中目录中的最后一个文件,而不是每个单元格中的文件。这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Profile_ManagerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.hidesAccessoryWhenEditing = YES;
}
cell.accessoryType = UITableViewCellAccessoryNone;
//cell.textLabel.text = @"No Ringtones";
//cell.textLabel.text = @"Test";
NSString *theFiles;
NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager directoryContentsAtPath:@"/Test"];
for (NSString *s in fileList){
theFiles = s;
}
cell.textLabel.text = theFiles;
return cell;
}
它加载正常,没有错误,当我使用NSLog 时,它列出了目录中的所有文件就好了。我什至尝试过[s objectAtIndex:indexPath.row],但我得到 objectAtIndex: 错误。有人有什么想法吗?
【问题讨论】:
-
也许您应该在标题中创建数组,以便您可以在主文件中的任何位置访问该文件。如果您不这样做,那么您如何设置表格项目的数量,除非您已经预先设置了数量,但是如果您让人们添加或删除文件,那么获取目录中的项目数量会更容易。跨度>
标签: ios uitableview nsarray nsfilemanager