我的UITableView是如何实例化自己的单元格的?

时间:2012-07-26 23:14:29

标签: uitableview

dequeueReusableCellWithIdentifier:正在实例化一个nib ??

Stack Trace

我问,因为它似乎实例化的细胞多于它一次在屏幕上显示的细胞。 (尽管少于比表中的总行数

我使用FRCTableViewDataSource将我的表格视图绑定到Core Data中的某些Artist对象。我不认为这很重要,它只是作为香草桌视图的数据源。

这里是他们实现的cellForRowAtIndexPath(我添加了日志语句)

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = nil;
    Class theCellClass = [self cellClassAtIndexPath:indexPath];
    if ([theCellClass isSubclassOfClass:[FRCTableViewCell class]])
        cellIdentifier = [theCellClass reuseIdentifier];
    NSLog(@"%@", cellIdentifier);
    UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:cellIdentifier];
    NSLog(@"%@", cell);

    ...

    return cell;
}

这是我对awakeFromNib的实现

- (void)awakeFromNib
{
    NSLog(@"waking");
}

控制台输出如下所示:

ArtistTableViewCell
waking
<ArtistTableViewCell: 0xc678ad0; baseClass = UITableViewCell; frame = (0 0; 295 50); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0xc6789f0>>

TL; DR我的表视图比表视图更具主动性。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您是否在单元格的笔尖中正确设置了重用标识符? 如果没有,每次都会得到一个新的单元格,因为重用ID不匹配。

否则,是的,如果没有任何东西可以出列,这个版本的dequeue将实例化一个nib。 从那里,它将创建你的单元格实例,从nib,yadyadayada唤醒。