【发布时间】:2013-04-03 09:55:37
【问题描述】:
我正在尝试为 iPhone 和 iPad 故事板使用一个类 (DetailCell)。 我有以下代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * cellIdentifier = @"DetailCell";
DetailCell * detailCell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (detailCell == nil) {
detailCell = [[DetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DetailCell"];
}
//cell customization here...
return detailCell;
}
它完美适用于 iPad,但不适用于 iPhone!所有标识符、连接和类设置正确。我还尝试擦除两个板上的单元格并创建新单元格。我实际拥有的:
在 iPad 上:
我在双端队列中获取单元格,因此它不会进入 if 并根据需要返回单元格。
在 iPhone 上:
deque 返回 nil,如果,它返回 DetailCell 但对其进行自定义不起作用。 (设置值前后所有网点均为零) 这种行为的原因是什么?
PS 在 iOS5 和 iOS6 上都
【问题讨论】:
-
dequeueReusableCellWithIdentifier:仅当具有给定标识符的任何单元格离开屏幕并排队时才返回单元格。您确定您的情况正在发生这种情况吗?
-
@nkongara in ios6 它无论如何都会返回单元格。但是在 iphone 上,它使用 init 创建单元格的次数与我的行数一样多!而且还是空桌子。
标签: iphone objective-c uitableview