UITableView 中的两个自定义单元格

Two customize cells in UITableView

我想知道是否可以将 2 个自定义单元格合二为一 UITableView

因为我想在一个视图中有两种不同类型的单元格:第一行会很大(屏幕截图上有白色背景),然后是简单的行(屏幕截图上有红色背景)。

告诉我这是否可能,以及如何实现:)

我让你看看我想做什么:

http://www.noelshack.com/2015-13-1427415385-sans-titre.png

或者在 table 单元格之后放一个 UIView 用于大标签?

有两种方法,假设大截图只在第一行。您可以设置 table 视图的 属性

tableView.tableHeaderView = myHugeImage;

否则,如果您使用 nibs 和自定义设计 2 行 类,则需要在 viewDidLoad 中调用以下代码。请注意,自定义 类 必须是 UITableViewCell

的子类
[tableView registerNib:[UINib nibWithNibName:@"bigrow" bundle:nil] forCellReuseIdentifier:@"big"]
[tableView registerNib:[UINib nibWithNibName:@"normal row" bundle:nil] forCellReuseIdentifier:@"normal"]

如果您使用 类 而没有笔尖,那么您将使用 registerClass:forCellReuseIdentifier 如果您使用 类 并直接在原型单元内设计单元,那么这些调用都不是必需的。

最后,里面tableView:cellForRowAtIndexPath:

if (indexPath.row == 0) {
    BigRowCell *c = [tableView dequeueReusableCellWithIdentifier:@"big" forIndexPath:indexPath];
    return c;
}
SmallRowCell *c = [tableView dequeueReusableCellWithIdentifier:@"normal" forIndexPath:indexPath];
return c;