为什么[[UIApplication sharedApplication]委托];返回一个nil对象 [英] Why does [[UIApplication sharedApplication] delegate]; return a nil object

查看:50
本文介绍了为什么[[UIApplication sharedApplication]委托];返回一个nil对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有多个视图的iphone应用程序以及相关的控制器和xib文件.在加载的第一个视图的控制器中,我试图访问该应用程序的委托,但返回的对象为nil

I have an iphone application with multiple views and related controllers and xib files. In the controller for the first view that is loaded I am trying to access the delegate for the application but the object that is returned is nil

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

有什么主意为什么会为零?

Any ideas why it would be nil?

推荐答案

因为尚未设置.UIApplication委托通常是从MainWindow nib文件中实例化和设置的.如果您在笔尖完全加载之前访问它(例如,同一笔尖中控制器中的init方法),则为nil.

Because it is not (yet) set. The UIApplication delegate is usually instantiated and set from the MainWindow nib file. If you access it before the nib is loaded completely (e.g. an init method in a controller in the same nib), it is nil.

这篇关于为什么[[UIApplication sharedApplication]委托];返回一个nil对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆