initwithstyle:reuseIdentifier: 未调用 [英] initwithstyle:reuseIdentifier: not called

查看:25
本文介绍了initwithstyle:reuseIdentifier: 未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建自己的自定义 UITableViewCell 以用作原型单元格的后端.在我的课程中,我覆盖了 initwithstyle:reuseIdentifier: 方法来进行一些自定义初始化,但我的初始化程序没有被调用.我在其中的第一行有一个断点,在 dequeueResusableCellWithIdentifier: 上也有一个断点.dequeueResusableCellWithIdentifier: 方法被调用,它返回一个初始化的单元格,但没有到达initwithstyle:reuseIdentifier: 中的断点.任何帮助都会很棒.

I'm creating my own custom UITableViewCell to use as the backend of a prototype cell. In my class I override the initwithstyle:reuseIdentifier: method to do some custom initialization, but my initializer is not called. I have a break point on the first line inside of it, as well as a break point on dequeueResusableCellWithIdentifier:. The dequeueResusableCellWithIdentifier: method is called, and it returns a initilized cell, but the break point in initwithstyle:reuseIdentifier: is not reached. Any help would be great.

推荐答案

如果你的单元格是从故事板原型(你在 IB 中声明为自定义类)创建的,那么它不会用 创建initWithStyle... 但是 initWithCoder: 而不是,就像从笔尖加载的任何其他对象一样.如果您有任何设置代码,它应该在那里或在 awakeFromNib 中.

If your cell is being created from a storyboard prototype (which you have declared as the custom class in IB) then it won't be created with initWithStyle... but initWithCoder: instead, like any other object loaded from a nib. If you have any setup code, it should be in there or in awakeFromNib.

这篇关于initwithstyle:reuseIdentifier: 未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆