dequeueReusableCellWithIdentifier为iPhone返回nil。在两个故事板中连接一个班级

时间:2013-04-03 09:55:37

标签: iphone objective-c uitableview

我正在尝试将一个类(DetailCell)用于iPhone和iPad故事板。 我有以下代码:

- (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上

我在deque中获取单元格,因此它不会进入if并根据需要返回单元格。

iPhone上的

deque返回nil,转到if,它返回DetailCell但是它的cusomization不起作用。 (所有出口在设定值之前和之后均为零) 这种行为的原因是什么?

在iOS5和iOS6上都是P.S

1 个答案:

答案 0 :(得分:0)

试试这个。     static NSString * cellIdentifier = @“DetailCell”;

DetailCell * detailCell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (detailCell == nil)
{
    detailCell = [[DetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"DetailCell"];

    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"YourNibName" owner:self options:nil];
    for (id oneObject in nib) if ([oneObject isKindOfClass:[DetailCell class]])
        cell = (DetailCell *)oneObject;
}
//cell customization here...
return detailCell;
相关问题