为什么不initWithRootViewController保留传递到它的viewController类?
-
20-08-2019 - |
题
我有一个自定义的viewController称为SourceListViewController,并且我添加它变成一个UINavigationController,那么该视图,其中被添加到iPhone应用程序的窗口。经过SourceListViewController到UINavigationController的后,我松开sourceListViewController。
SourceListViewController *sourceListVC = [[SourceListViewController alloc] initWithNibName:@"SourceListViewController" bundle:nil];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:sourceListVC] autorelease];
[sourceListVC release];
当我做到这一点,该视图被加载到电话后的应用程序将崩溃。当我注释掉最后一行,应用程序做工精细。是不是应该initWithRootViewController保留sourceListVC的副本?
解决方案
正在自动释放navigationController。所以,如果navigationController被自动释放(这将在未来runloop可能发生),那么这样就会sourceListVC。
不隶属于 StackOverflow