0

我有自定义且非常简单的 UITableViewCell。我只想通过在 ios 6 中使用新技术来初始化我的表格视图,即注册类并在带有标识符的双端队列单元格之后。所以我有 UITableViewController,在 tableview 里面我有一个原型单元格,这是它的图像。在此处输入图像描述

起初我忘记在 Table View 控制器内的 viewDidLoad 方法中注册该类,它工作正常。这是代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CustomCell *cell = [tableView  dequeueReusableCellWithIdentifier:@"customCellIdentifier" forIndexPath:indexPath];

    return cell;
}

但在这种情况下

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

在单元初始化过程中不调用。

在我将注册类功能放入 viewdidload 之后。这是代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@"customCellIdentifier"];

}

在它 - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier开始调用之后,但在这种情况下,当我尝试调试时,单元格绝对是空的,在 initwithstyle 方法中,所有的出口都是零。这是怎么回事?我做错了什么?

4

1 回答 1

0

如果您已将单元格定义为 nib/storyboard 文件中表格视图的原型单元格,那么您不必注册它,这是自动完成的。但在这种情况下,initWithCoder:调用从笔尖/故事板实例化的单元格。

于 2013-06-06T18:16:07.570 回答