我的XIB for iPad / iPhone中的两个UITableViewCells

时间:2013-04-15 16:06:32

标签: objective-c xcode uitableview xib

我正在尝试使用两种格式不同的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,它会给我一个错误: invalid nib registered for identifier (historyCellType) - nib must contain exactly one top level object which must be a UITableViewCell instance'

有没有解决这个问题?

谢谢!

1 个答案:

答案 0 :(得分:13)

在iPad和iPhone上使用不同单元格的最佳方法是使用2个笔尖: HistoryCell~iphone.xib HistoryCell~ipad.xib

你必须注册你的笔尖:

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

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

相关问题