使用前向声明调用类时 IBOutlet 为 NIL?

发布于 2024-08-25 22:01:37 字数 271 浏览 1 评论 0原文

我对此遇到了很大的问题,所以我画了一个图表...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福丶如此 2024-09-01 22:01:37

这完全取决于你什么时候给班级打电话。在使用 initWithNibName 创建视图控制器之后,实际上还没有连接任何东西 - 只有在创建视图之后,才会创建并连接 IBOutlet。

一个技巧是您可以简单地向视图控制器询问 .view,如下所示:

myViewController.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:

myViewController.view;

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 in viewWillAppear you use those properties to set values for your outlets.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文