我有一个基于导航的 iPhone 应用程序。当您按下 tableview 中的一个单元格时,一个新的 UIViewController 被推送到导航堆栈。在这个视图控制器中,我在 viewDidLoad 方法中设置了一个自定义 titleView:
- (void)viewDidLoad {
[super viewDidLoad];
// Setup custom navigation title
[self setTitle:@"Mediaportal"];
navItem = [[NavigationBarTitleItemViewController alloc] initWithNibName:@"NavigationBarTitleItem" bundle:nil];
[navItem setTitle:[theServer name]];
[navItem setSubTitle:@""];
[self.navigationItem setTitleView:navItem.view];
…
}
一旦我切换回 RootViewController:
[self.navigationController popToRootViewControllerAnimated:YES];
应用程序崩溃并出现以下错误(NSZombieEnabled=YES):
*** -[CALayer retain]: message sent to deallocated instance 0x5a5fd80
从我可以看到的 RootViewController 仍然尝试访问自定义 titleView,它已被第二个视图控制器释放。一旦我注释掉代码中的自定义 titleView 部分,该应用程序就会工作。在释放第二个 ViewController 之前,我尝试将 navigationItem.titleView 设置为 nil (如在苹果文档中找到的),但这无济于事。
你有什么提示我可以做些什么来防止这次崩溃吗?
谢谢,马克。