使用前向声明调用类时 IBOutlet 为 NIL?
我对此遇到了很大的问题,所以我画了一个图表...
alt text http://tomsfil.es /7bdead0a.png
我成功地达到了 A 类 - 方法 B,但此时 IBOutlet Z 为零? :( 有什么想法吗?
注意 有人告诉我这可能是过度释放并使用 NSZombieEnabled 但这让我很困惑
I have been having huge issues with this, so I drew a diagram...
alt text http://tomsfil.es/7bdead0a.png
I successfully get to the CLASS A - METHOD B but at that point, IBOutlet Z is Nil? :(
Any ideas?
note
Somebody told me it might be an Overrelease and to use NSZombieEnabled but that confused me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这完全取决于你什么时候给班级打电话。在使用 initWithNibName 创建视图控制器之后,实际上还没有连接任何东西 - 只有在创建视图之后,才会创建并连接 IBOutlet。
一个技巧是您可以简单地向视图控制器询问 .view,如下所示:
然后视图将被创建并且 IBOutlet 将存在。不过,更好的方法是在您设置的视图控制器上创建属性,然后在 viewDidLoad 或 viewWillAppear 中使用这些属性来设置插座的值。
It's all a matter of when you call the class. Right after you create a view controller with initWithNibName, nothing is actually wired up yet - it's only after the view is created that IBOutlets are created and wired in.
One trick is that you can simply ask the view controller for .view, like so:
Then the view will be created and the IBOutlet will exist. A better method though, is to create properties on the view controller that you set, and then either in
viewDidLoad
, or inviewWillAppear
you use those properties to set values for your outlets.