我想列出在TableView中的铃声目录的内容,但是,我只获取目录中所有单元格中的最后一个文件,而不是每个单元格中的文件。这是我的代码:在UITableView中列出目录的内容
- (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:错误。有人有主意吗?
也许你应该在头文件中创建数组,这样你就可以访问主文件中任何地方的文件。如果你不这样做,那么除非你已经预先设置了这个数字,但是如果你有人添加文件或者删除它,那么你怎样才能设置表格项的数量,这将更容易得到目录中项目的数量。 – Maximilian 2011-10-01 18:00:23