因此,在內存不足的情況下,我的根視圖被卸載。這是預料之中的事情。但是,如何處理需要彈出的模式/推式視圖控制器,因爲它們引用主navigationController?我在推視圖控制器中有一個自定義完成按鈕,它調用[self.navigationController popViewControllerAnimated:YES]。如果根視圖已被卸載,則會導致訪問錯誤。有一個更好的方法嗎?防止在uinavigationcontroller設置中popViewControllerAnimated的訪問不良崩潰
我的設置是 AppDelegate中有一個NavigationController 這NavigationController有MainViewController
//MainViewController.m
- (IBAction)showAnotherController:(id)sender
{
AnotherViewController * anotherViewController;
anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
}
//...Here I can simulate a memory warning to force unloading of MainViewController's view
//in AnotherViewController.m, called from a custom toolbar item
- (IBAction)done:(id)sender
{
[self.navigationController popViewControllerAnimated:YES]; // bad access here, looks like self.navigationController is no longer available. Am I doing this wrong?
}
viewDidUnload方法只是卸載視圖控制器的視圖,而不是視圖控制器本身。根控制器必須在那裏。你可以發佈崩潰? – Jorge 2011-04-03 10:13:32
的確如此。因爲self.navigationController不再存在,所以我只是在調試器卡在行[self.navigationController popViewControllerAnimated:YES]時得到一個EXC_BAD_ACCESS。 – akaru 2011-04-03 19:24:55