gpt4 book ai didi

ios - 我可以在多个 tableView 中使用单个原型(prototype)单元格吗?

转载 作者:IT王子 更新时间:2023-10-29 08:08:50 25 4
gpt4 key购买 nike

我在两个不同的 Controller 中有两个不同的 TableView 。但是我需要在其中显示的单元格看起来完全相同。我在一个 tableView 中创建了一个原型(prototype)单元格,并将 UiTableViewCell 子类化。现在,如果我想在不同的 Controller 中使用相同的单元格,我该如何使用它?

如果我只是在新 Controller 中导入该 customCell 文件并使用 Storyboard 中给定的相同标识符将其双端队列,它将无法工作。它说

Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

所以,很明显这意味着,单元格为零。那么如何从 Storyboard 中实例化相同的单元格呢?是否有可能或者我是否也必须为新表创建一个不同的 customCell?

最佳答案

K.. 我明白了。首先,

I can NOT use one prototype cell in two different tableview. But, I can use the same tableViewCell subclass in two different tableviews.

要实现它,只需从一个 Controller 复制原型(prototype)单元并将其粘贴为另一个 tableview 的原型(prototype)单元。粘贴的表格 View 的类保持不变。只需更改 reuseIdentifier。并使用它。

编辑:如果您的单元格具有相当复杂的 UI,那么单独为单元格创建单独的 xib 更有意义。然后以编程方式 register the xib与 TableView 。这样,您将只有一个单元格副本,并且在 ui 发生更改时可以更好地维护它。

关于ios - 我可以在多个 tableView 中使用单个原型(prototype)单元格吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13005154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com