如何销毁由pushViewController添加的视图?

发布于 2024-09-17 18:48:10 字数 129 浏览 7 评论 0原文

通过pushViewController方法添加视图后,导航栏中将有一个后退按钮,用于将视图从堆栈中弹出。但是,iOS似乎在将视图从堆栈中弹出后不会销毁该视图,那么什么时候会销毁它呢?我们可以在弹出视图时手动销毁它吗?

After adding a view by pushViewController method, there will be a back button in the navigation bar to pop the view off the stack. However, it seems that iOS won't destroy the view after popping it off the stack so when will it be destroyed? Can we destroy it manually when popping out the view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以为你会在 2024-09-24 18:48:10

一般来说,模式是这样的:

- (void)pushSomeViewControllerOnStack
{
    SomeViewController* someViewController = [[SomeViewController alloc] initWithNibName:@"SomeView" bundle:nil];
    [self.navigationController pushViewController:someViewController animated:YES];
    [someViewController release];
}

换句话说,导航控制器将自己retain视图控制器,这意味着您需要release code> 你自己,因为有一个 init。导航控制器还将在适当的时候负责释放该控制器。

Generally the pattern is like this:

- (void)pushSomeViewControllerOnStack
{
    SomeViewController* someViewController = [[SomeViewController alloc] initWithNibName:@"SomeView" bundle:nil];
    [self.navigationController pushViewController:someViewController animated:YES];
    [someViewController release];
}

In other words, the navigation controller will do its own retain of the view controller, which means you also need to release it yourself, since there's an init. The navigation controller will also take care of releasing this controller when appropriate.

濫情▎り 2024-09-24 18:48:10

您应该在 UIViewController 子类中实现 viewDidUnloaddealloc 方法。

当 UINavigationController 将视图控制器从其堆栈中弹出时,这些方法中的代码将被执行。

您应该阅读 iOS 视图控制器编程指南:导航控制器 来自 Apple iOS 开发人员库的文档以及 UINavigationControllerUIViewController< /code>类,以便您更好地了解视图控制器生命周期以及发生各种应用程序事件时会发生什么。

You should implement the viewDidUnload and dealloc methods within your UIViewController subclasses.

When a UINavigationController pops a view controller off its stack the code within those methods will be executed.

You should read the View Controller Programming Guide for iOS: Navigation Controllers documentation from Apple's iOS Developer Library as well as the class reference documentation for the UINavigationController and UIViewController classes so that you will better understand the view controller life cycle and what to expect when various application events occur.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文