Initializing a view with custom initWithCoder

风流意气都作罢 提交于 2019-12-05 01:30:46

You can't modify the initWithCoder: method like that because the method is defined in a protocol you don't control. Instead you need to either call the setTitle: method after the object has been created, possibly in awakeFromNib, or from the owning controller.

You don't call initWithCoder yourself, usually, so you can't pass custom parameters to it. That method would be called by the nib loading mechanism and you don't have control over it.

You certainly wouldn't call it from awakeFromNib - the object would already have been initialised by that point so you couldn't re-call it.

The simplest solution is to expose your custom parameters as properties and just set them after you've created the view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!