nib 中的自定义视图实例化为父类型
我创建了一个继承自 UILabel 的自定义类。我在笔尖中放置了一个 UILabel 并将标签的类设置为我的自定义类。但是,当调用 viewDidLoad
方法时,视图属于 UILabel
类,而不是我的自定义类。
有什么想法吗?
I've created a custom class inheriting from UILabel. I placed a UILabel in my nib and set the class of the label to my custom class. However, when the viewDidLoad
method is called, the view is of the class UILabel
instead of my custom class.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够在测试项目中创建 CustomLabel 的实例。我所做的不同之处在于,我没有拖动 UILabel,而是将 CustomLabel 的实例拉入视图中。
我针对最新 sdk 的目标实现了 awakeFromNib,如下所示。
几个谜团...
我在 CustomLabel 中实现了 init 和 initWithFrame,从笔尖加载视图的机制都没有调用它们。
I was able to create an instance of my CustomLabel in a test project. What I did differently was instead of dragging a UILabel, I pulled in an instance of CustomLabel into the view.
I implemented awakeFromNib against a target for the latest sdk as follows.
Couple of mysteries...
I implemented init and initWithFrame in CustomLabel, neither was called by the machinery that loads the view from the nib.