gpt4 book ai didi

objective-c - 我的 XIB for iPad/iPhone 中的两个 UITableViewCells

转载 作者:行者123 更新时间:2023-12-02 05:43:00 24 4
gpt4 key购买 nike

我正在尝试使用两种不同格式的 UITableViewCells,具体取决于它是 iPad 还是 iPhone。两个单元格显示相同的信息,但 iPad 单元格的高度减半,宽度加倍。因此信息显示在一行而不是两行。

在我的 cellforRowatIndexPath 中,

我正在放代码:

HistoryCell *cell;
if (self.isiPad) {
cell = [self.tableView dequeueReusableCellWithIdentifier:@"historyiPadCellType" forIndexPath:indexPath];

}
else{
cell = [self.tableView dequeueReusableCellWithIdentifier:@"historyCellType" forIndexPath:indexPath];

}

然而,如果我在同一个 XIB 中有 2 个 UItableViewCells,它会给我一个错误:为标识符 (historyCellType) 注册的 nib 无效 - nib 必须恰好包含一个顶级对象,该对象必须是 UITableViewCell 实例'

有办法解决这个问题吗?

谢谢!

最佳答案

为 iPad 和 iPhone 使用不同单元格的最佳方式是使用 2 个 Nib :HistoryCell~iphone.xibHistoryCell~ipad.xib

而且你必须注册你的 Nib :

[self.tableView registerNib:[UINib nibWithNibName:@"HistoryCell" bundle:nil] forCellReuseIdentifier:@"historyCellType"];

系统根据当前设备自动加载 xib。

关于objective-c - 我的 XIB for iPad/iPhone 中的两个 UITableViewCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16019807/

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