选项卡式应用程序导航控制器:按下选项卡时如何释放堆叠的 UIViewController?

发布于 2024-12-11 07:23:37 字数 229 浏览 0 评论 0原文

我有一个选项卡式应用程序,选项卡中有导航控制器,其中有视图控制器。当我按下某个选项卡项目并深入视图控制器层次结构(由导航控制器维护)时,直接按下选项卡项目会发生什么?恕我直言,所有视图控制器都在内存中的堆栈上,如果我开始从第一个视图控制器深处再次导航,那么我会将视图控制器的副本放在导航堆栈上。我应该如何进行正确的内存管理?恕我直言,当用户单击某个选项卡项时,我需要释放(弹出)屏幕上的所有视图控制器(第一个视图控制器除外)。如何实现这一目标?

I have a tabbed application with navigation controllers in tabs and view controller in them. When I press some tab item and go deep inside view controller hierarchy (that is maintained by navigation controller), what happens when I press tab item directly? IMHO all the view controller are on stack in memory and if I start navigating again from the the first view controller deep then I'm putting a copies of view controller on navigation stack. How should I do proper memory management? IMHO i need to release (pop) all view controller that are on screen (EXCEPT the first one) when user click some tab item. How to achieve that?

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

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

发布评论

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

评论(1

尸血腥色 2024-12-18 07:23:37

系统将在需要内存时卸载不需要的视图(并在需要时重新加载它们),因此如果您正确实现了 viewDidUnloadreceivedMemoryWarning 方法,你应该没问题。视图控制器本身几乎不占用任何内存(除非您自己分配了大量的东西)。在任何情况下,它们都不会分配在堆栈上,因为它们是分配在堆上的对象(一般目标 c 经验法则)。当您推送视图控制器时,它会被保留,当您弹出视图控制器时,它会被释放。通常,您不会期望每个选项卡中的导航控制器会弹出回根目录,因为您按下了另一个选项卡,但如果您确实想这样做,则可以使用 popToRootViewController 方法。

The system will take care of unloading un-needed views when it needs memory (and reloading them when they are needed), so if you have implemented the viewDidUnload and receivedMemoryWarning method correctly, you should be fine. The view controllers themselves take hardly any memory (unless you've allocated tons of stuff yourself). In any case they are not allocated on the stack, as objects they are allocated on the heap (general objective c rule of thumb). When you push a view controller it is retained, when you pop a view controller it is released. Usually you wouldn't expect the navigation controller in each tab to pop back to root because you pressed another tab, but if you really want to do that then you can use popToRootViewController method.

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