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

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

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


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

查看所有标签

猜你喜欢:

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

Nine Algorithms That Changed the Future

Nine Algorithms That Changed the Future

John MacCormick / Princeton University Press / 2011-12-27 / GBP 19.95

Every day, we use our computers to perform remarkable feats. A simple web search picks out a handful of relevant needles from the world's biggest haystack: the billions of pages on the World Wide Web.......一起来看看 《Nine Algorithms That Changed the Future》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

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

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具