【问题标题】:Why doesn't initWithRootViewController retain the viewController Class that is passed into it?为什么 initWithRootViewController 不保留传入的 viewController 类?
【发布时间】:2009-06-28 14:11:04
【问题描述】:

我有一个名为 SourceListViewController 的自定义 viewController,我将它添加到 UINavigationController 中,然后将其视图添加到 iphone App 的窗口中。在将 SourceListViewController 传递给 UINavigationController 之后,我释放了 sourceListViewController。

SourceListViewController *sourceListVC = [[SourceListViewController alloc] initWithNibName:@"SourceListViewController" bundle:nil];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:sourceListVC] autorelease];
[sourceListVC release];

当我这样做时,应用程序会在视图加载到手机后崩溃。当我注释掉最后一行时,该应用程序运行良好。 initWithRootViewController 不应该保留 sourceListVC 的副本吗?

【问题讨论】:

    标签: iphone uinavigationcontroller


    【解决方案1】:

    您正在自动释放 navigationController。因此,如果 navigationController 被自动释放(这可能会在下一个 runloop 中发生),那么 sourceListVC 也会如此。

    【讨论】:

    • 这并不意味着 sourceListVC 被保留。是不是这样,当你释放 NavigationController 时,它的所有 ViewController 也都释放了,NVC 不保留根视图控制器?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-02
    • 1970-01-01
    相关资源
    最近更新 更多