如何以编程方式配置UITableViewCell?

时间:2014-09-12 22:30:46

标签: objective-c uitableview

我正在尝试从代码中创建UITableView(以前从未这样做过),它将显示在UIPopover中。我想列出目录的内容(仅限文件名)。这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"FilenameCell";

    UITableViewCell *cell = (UITableViewCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    cell.textLabel = fileList[0];

    return cell;
}

这显然不起作用,我收到一个错误:“分配给只读属性”。所以,问题是:在这种情况下如何设置单元格的数据?

1 个答案:

答案 0 :(得分:1)

您需要设置textLabel text属性(我确定这只是您的错误):

cell.textLabel.text = fileList[0];
相关问题