UINavigation 控制器中未使用的视图会发生什么情况?

发布于 2024-10-14 16:53:04 字数 234 浏览 2 评论 0原文

我正在 iOS 中实现一个购物车。

我正在使用 UINavigationController 来显示流程每个步骤的 UIViewControllers。用户可以使用后退按钮进行更改。

但他们提交订单后我不希望他们回去。使用导航控制器显示没有后退按钮的视图的正确方法是什么?

当你这样做时,之前的 UIViewController 会发生什么?他们被解除分配了吗?显然我不需要它们。我必须手动取消分配它们吗?

I am implementing a shopping cart in iOS.

I am using a UINavigationController to show UIViewControllers for each step of the process. Users can use the back button and change things.

But after they submit the order I don’t want them to go back. What is the correct way to show a view without the back button using the navigation controller?

When you do that, what happen to the previous UIViewControllers? Are they deallocated ? Obviously I don’t need them. Do I have to manually deallocate them?

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

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

发布评论

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

评论(2

岁月打碎记忆 2024-10-21 16:53:04

您必须取消分配这些视图控制器。否则它们就会开始泄漏。我想,您会以某种方式推动视图控制器,类似于以下内容。

MyViewController *myViewController = [[MyViewController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];

如果您这样做,以后就无需担心这些视图控制器。当 UINavigationController 完成后,它们将被释放。

隐藏后退按钮:在最后一个视图控制器的 loadView 方法中添加以下行。

[self.navigationItem setHidesBackButton:YES];

You have to deallocate those view controllers. They will start to leak, otherwise. I guess, you would be pushing the view controllers somehow similar to the following.

MyViewController *myViewController = [[MyViewController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];

If you are doing like this, you have no need to worry about those view controllers, later. They will be released by the UINavigationController when it is done them.

Hiding the back button: Add the following line in the loadView method of your last view controller.

[self.navigationItem setHidesBackButton:YES];
末が日狂欢 2024-10-21 16:53:04

您可以告诉它转到特定的视图控制器,方法如下:

[myNavController popToRootViewControllerAnimated:YES];

或者,还有一个 UINavigationController 方法为其提供一组视图控制器,它应该显示第一个视图控制器。

You can tell it to go to a specific view controller either with something like:

[myNavController popToRootViewControllerAnimated:YES];

Or, there's also a UINavigationController method to give it an array of view controllers, it should present the first one.

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