UINavigation 控制器中未使用的视图会发生什么情况?
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须取消分配这些视图控制器。否则它们就会开始泄漏。我想,您会以某种方式推动视图控制器,类似于以下内容。
如果您这样做,以后就无需担心这些视图控制器。当 UINavigationController 完成后,它们将被释放。
隐藏后退按钮:在最后一个视图控制器的
loadView
方法中添加以下行。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.
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.您可以告诉它转到特定的视图控制器,方法如下:
或者,还有一个 UINavigationController 方法为其提供一组视图控制器,它应该显示第一个视图控制器。
You can tell it to go to a specific view controller either with something like:
Or, there's also a UINavigationController method to give it an array of view controllers, it should present the first one.