objective-c – 为什么不调用自定义基于nib的表单元格的init方法

栏目: Objective-C · 发布时间: 5年前

内容简介:而不是 – (id)init被调用 – (id)initWithCoder:(NSCoder *)将调用aDecoder.此时,如果您需要访问可以覆盖的出口 – (void)awakeFromNib,它将被连接起来,这将在连接对象后调用.翻译自:https://stackoverflow.com/questions/6942152/why-does-the-init-method-of-a-custom-nib-based-table-cell-not-get-called

我有一个基于nib的表视图单元格,我在Interface builder中创建.我将表视图单元的类设置为从UITableViewCell扩展的FooTableViewCell.

在FooTableViewCell中,我重写了这样的init方法:

-(id)init{

    if ((self = [super init])){
      // My init code here
    }
    return self;
}

我现在期望在实例化时调用它.但是会显示表视图,但从不调用该方法.

我可以解决这个问题,但我想完全理解它,对我而言,如果没有调用init方法,对象是如何生存的还不清楚.

而不是 – (id)init被调用 – (id)initWithCoder:(NSCoder *)将调用aDecoder.此时,如果您需要访问可以覆盖的出口 – (void)awakeFromNib,它将被连接起来,这将在连接对象后调用.

翻译自:https://stackoverflow.com/questions/6942152/why-does-the-init-method-of-a-custom-nib-based-table-cell-not-get-called


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to Computer Science Using Python

Introduction to Computer Science Using Python

Dierbach, Charles / 2012-12 / $ 133.62

Introduction to Computer Science Using Python: A Computational Problem-Solving Focus introduces students to programming and computational problem-solving via a back-to-basics, step-by-step, objects-la......一起来看看 《Introduction to Computer Science Using Python》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具