我有 n 个文件。我将 n 个文件附加到表视图中。实际上,n 个文件属于一个文件夹。但是当我将这些文件附加到表视图时,它们被附加到表视图中,并以单行分隔通过逗号。如何在表格视图中将它们拆分为不同的行。请给我建议并帮助我。
问问题
196 次
3 回答
1
将文件名放在一个数组中,比如说fileNames
,它们在viewDidLoad
方法中找到。
并实现如下方法:
-(NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
return [fileNames count];
}
-(UITableViewCell*)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.textLabel.text = [fileNames objectAtIndex:indexPath.row];
return cell;
}
于 2012-04-13T11:59:36.107 回答
0
将您的文件列表存储在一个数组中,每个数组元素有一个文件名,并用于indexPath.row
选择正确的文件名。
componentsSeparatedByString:
如果您需要分解单个字符串,请使用。
于 2012-04-13T12:00:26.800 回答
0
于 2012-04-13T12:00:45.373 回答