更新:我在調試時犯了一個錯誤 - 此問題不是相關的 - 請參閱下面的註釋。UIViewController在解除時未收到dealloc或viewDidUnload
注:我使用的自動引用計數
當我的應用程序啓動 - 我目前有presentViewController:animated:completion
一個UINavigationController
內部的視圖控制器。該視圖控制器將第二個視圖控制器加載到導航堆棧上。第二個視圖控制器使用[self.presentingViewController dismissViewControllerAnimated:YES completion:nil]
來解散它自己。我的問題是,在第一個視圖控制器中都不會調用dealloc和viewDidUnload。但是,通過儀器,我可以看到一旦所提交的視圖控制器被解僱,視圖控制器就不再分配。呈現的第一個視圖控制器的代碼是
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// check if our context has any accounts
if([self.accounts count] == 0)
{
// Display the Add Account View Controller
MySettingsViewController *settingsVC = [[MySettingsViewController alloc] initWithNibName:@"MySettingsViewController" bundle:nil];
settingsVC.appContext = self.appContext;
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:settingsVC];
navVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
// Display the Add Account View Controller
}
else
{
navVC.modalPresentationStyle = UIModalPresentationFormSheet;
}
[self presentViewController:navVC animated:YES completion:nil];
}
}
所以,我沒有那個周圍應堅持settingsVC任何引用,但我不知道爲什麼我的dealloc不會被調用。任何幫助都會很棒。
我是個白癡。我把dealloc方法放在錯誤的視圖控制器中進行測試。所以我的dealloc被調用,這是有道理的。 – Brian 2012-02-10 16:09:23