2015-09-27 23 views
0

我想從我的appdelegate注入一個對uitableviewcontroller屬性的引用。第一個是成功的 - 我能夠從我的uitableviewcontroller引用xmppStream,但第二個似乎在某處銷燬引用,我不知道爲什麼。navigationController.topViewController vs storyboard

首先 - 確定,uitableviewcontroller中的xmppStream不是零;

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; 

PhoneNumberTableViewController *myViewController = (PhoneNumberTableViewController *)navigationController.topViewController; 

[myViewController setXmppStream:[self xmppStream]]; 

第二 - 得到一個引用,但被銷燬,即在uitableviewcontroller xmppStream是零?

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; 

PhoneNumberTableViewController *tv = [sb instantiateViewControllerWithIdentifier:@"UserRegistration"]; 

[tv setXmppStream:[self xmppStream]]; 

任何幫助將不勝感激。

感謝

+0

'instantiateViewControllerWithIdentifier' *實例化一個viewController,因此得到一個新的對象,這個對象因爲不再需要而被丟棄了/沒有強引用 – luk2302

回答

1

什麼都要嘗試是使PhoneNumberTableViewController一個屬性,當你需要使用的是使用該變量。像

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; 

_myViewController = (PhoneNumberTableViewController *)navigationController.topViewController; 

[myViewController setXmppStream:[self xmppStream]];