【发布时间】:2012-02-10 15:35:47
【问题描述】:
更新:我在调试中犯了一个错误 - 这个问题无关紧要 - 请参阅下面的评论。
注意:我正在使用自动引用计数
当我的应用程序启动时 - 我在 UINavigationController 和 presentViewController:animated:completion 中显示了一个视图控制器。该视图控制器将第二个视图控制器加载到导航堆栈上。第二个视图控制器使用[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 被调用,这是有道理的。
标签: ios ios5 uiviewcontroller uikit automatic-ref-counting