子类化 UIBarButtonItem
我正在尝试创建 UIBarButtonItem 类的子类。该按钮已添加到 nib 文件中,并且我将其类设置为界面生成器中的自定义类。现在,如果这是一个 UIView
类或子类,我将重写 - (id)initWithCoder:(NSCoder *)decoder
方法来启动额外的自定义,但是 UIBarButtonItem缺少这样的方法。我尝试重写其
-(id)init
方法,但没有成功,因此不会被调用。我的问题是,我应该从哪里开始定制?我需要重写什么方法?
I'm trying to make a subclass of the UIBarButtonItem
class. The button is added in the nib file and I set its class to my custom class in the interface builder. Now if this was a UIView
class or subclass I would have override the - (id)initWithCoder:(NSCoder *)decoder
method to start the extra customization, however UIBarButtonItem
lacks such a method. I tried to override its -(id)init
method but with no success, it doesn't get called. My question, where should I start my customization? What method do I need to override?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为你用的是IB。当您在 IB 中创建对象时,它不会调用该类的 init 方法,而是使用该对象的存档版本。因此,要进行自定义初始化,请改用此方法:
It's because you use IB. When you create an object in IB it does not call the init method for the class, it uses the archive version of the object. So to make custom initializations use this method instead: