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

Ala*_*lan 2 xcode objective-c 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];

}
Run Code Online (Sandbox Code Playgroud)

但是,如果我在同一个XIB中有2个UItableViewCells,它会给我一个错误: invalid nib registered for identifier (historyCellType) - nib must contain exactly one top level object which must be a UITableViewCell instance'

有没有什么办法解决这一问题?

谢谢!

小智 13

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

你必须注册你的笔尖:

[self.tableView registerNib:[UINib nibWithNibName:@"HistoryCell" bundle:nil] forCellReuseIdentifier:@"historyCellType"];
Run Code Online (Sandbox Code Playgroud)

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