【问题标题】:iOS UITableView with dynamic prototypes and custom cell带有动态原型和自定义单元格的 iOS UITableView
【发布时间】:2013-11-22 13:50:33
【问题描述】:

我有带有动态原型单元格的 tableview 的 uitableviewcontroller,甚至我将单元格样式更改为字幕或其他内容,或者我添加了附件,我的单元格始终显示为基本样式单元格。

这是我的 cellForRowAtIndexPath 函数:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger row = indexPath.row;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    if (_dataArray && row < self.dataArray.count) {
        cell.textLabel.text = self.dataArray[row];
    }

    return cell;
}

编辑:有些东西我不明白,也许有人可以解释一下。早些时候,当我显示我的表格视图控制器时,我的应用程序崩溃了,所以我不得不将它添加到 viewDidLoad 方法中:

[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdentifier];

之后应用程序没有崩溃,但导致我无法更改单元格样式。现在我可以删除它,我的应用程序不会崩溃,我可以更改单元格样式。为什么?

我做错了什么?

【问题讨论】:

    标签: ios uitableview storyboard


    【解决方案1】:

    确保在情节提要中设置单元格的标识符。

    还可以使用标签来修改故事板中的 UI 元素:

    UIImageView *imageView = (UIImageView *)[cell viewWithTag:1];
    UILabel *eventNameLabel = (UILabel *)[cell viewWithTag:2];
    

    【讨论】:

    • 是的,标识符已设置。我使用基本单元格样式,但是当我选择例如披露指示器作为附件视图,然后它没有显示。它会在我删除注册单元格时显示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    相关资源
    最近更新 更多