我正在經歷一個奇怪的行爲。 在視圖控制器我想保留我的應用程序代理的參考([[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類寫得很好。
你有什麼想法嗎?
我迷路了......
感謝