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

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

内容简介:而不是 – (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


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

查看所有标签

猜你喜欢:

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

Real-Time Rendering, Third Edition

Real-Time Rendering, Third Edition

Tomas Akenine-Moller、Eric Haines、Naty Hoffman / A K Peters/CRC Press / 2008-7-25 / USD 102.95

Thoroughly revised, this third edition focuses on modern techniques used to generate synthetic three-dimensional images in a fraction of a second. With the advent or programmable shaders, a wide varie......一起来看看 《Real-Time Rendering, Third Edition》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

SHA 加密
SHA 加密

SHA 加密工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具