1
我有一個名爲SourceListViewController的自定義viewController,我將它添加到UINavigationController中,然後將其視圖添加到iphone應用程序的窗口中。將SourceListViewController傳遞給UINavigationController後,我釋放sourceListViewController。爲什麼initWithRootViewController不保留傳入它的viewController類?
SourceListViewController *sourceListVC = [[SourceListViewController alloc] initWithNibName:@"SourceListViewController" bundle:nil];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:sourceListVC] autorelease];
[sourceListVC release];
當我這樣做時,應用程序會在視圖加載到手機後崩潰。當我註釋掉最後一行時,該應用程序正常工作。是不是initWithRootViewController應該保留sourceListVC的副本?
這並不意味着sourceListVC被保留。是不是像這樣,當你釋放NavigationController時,它的所有ViewController都被釋放,並且NVC不保留根視圖控制器? – karim 2011-01-26 11:21:44