我正在经历一个奇怪的行为。 在视图控制器我想保留我的应用程序代理的参考([[UIApplication sharedApplication] delegate]
)self.appDelegate = [[UIApplication sharedApplication] delegate];总是0x0
所以我有一个属性,当我的控制器实例化时,我设置了。 所有工作在模拟器上的设备上,我的属性总是在调试器中为0x0。
我写了这个代码进行测试:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
AppDelegate *localVar = [[UIApplication sharedApplication] delegate]; // OK
self.appDelegate = [[UIApplication sharedApplication] delegate]; // 0x0
}
return self;
}
我深信的appDelegate设置,我也写了二传,以验证它被称为
- (void)setAppDelegate:(AppDelegate *)delegate
{
appDelegate = delegate; // delegate is a valid address but appDelegate is still showing 0x0
}
我想知道如果我的AppDelegate类写得很好。
你有什么想法吗?
我迷路了......
感谢