【问题标题】:ios 6 strange behavior on custom UITableViewCell initializationios 6自定义UITableViewCell初始化的奇怪行为
【发布时间】:2013-06-07 02:16:07
【问题描述】:

我有自定义且非常简单的 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 方法中,所有的出口都是零。 这是怎么回事?我做错了什么?

【问题讨论】:

    标签: ios6 uitableview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2014-10-06
      • 2011-08-19
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      相关资源
      最近更新 更多