使用 UINavigationController 进行内存管理 [英] MemoryManagement with UINavigationController
问题描述
我的 NavigationController 有一个问题".实际上,在我看来,这种行为似乎是有意为之.
I have an "issue" with my NavigationController. Actually it seems to me, that this behavior seems to be intended.
我的应用程序使用 SplitViewController,MasterView 使用 TableViewController,DetailView 使用 NavigationController.
My App uses a SplitViewController, using a TableViewController for the MasterView and a NavigationController for the DetailView.
我有 4 个视图,可以从一个视图切换到另一个视图.我观察到,每次使用 NavigationController 按钮之一更改视图时,内存消耗都会增加近 1.5MB.
I have 4 views, which i can switch from each to another. What I observed is that every time I use one of the NavigationController buttons to change the View the memory consumption increases by almost 1.5MB.
使用 NavigationController 的后退按钮,当使用的内存减少时,视图似乎可以正确释放.
Using the back-button of the NavigationController the views seem to get released correctly as the used memory decreases.
我读到每次切换视图时都将视图放在堆栈上,但实际上这不是我需要的(至少我希望如此,因为在某种程度上我依赖 viewdidload-method 来更新内容,我通过 NSNotification 将其传递给每个视图.到那时,如果所有视图都可以共享传递的 userInfo,那就太好了,但那是一个不同的故事......).
I read that the views are put on a stack every time i switch them, but actually that is not what I need (At least I hope so, because at a certain degree I rely on the viewdidload-method to update the content, which I pass via NSNotification to each view. At that point it would be nice if all views could share that passed userInfo, but that's a different story...).
所以我正在寻找一种方法来替换 NavigationController 视图堆栈上的最新 ViewController.我不需要像 100 次观看的历史记录,其中 40 次观看实际上总是相同的.我只找到了有关使用后退按钮后内存未释放的答案.因此,我假设当前的行为是预期的.
So what I'm looking for is a way to replace the newest ViewController on the NavigationController view stack by the one. I don't need a history of like 100 views where like 40 views always are actually the same. I only found answers about memory not getting released after using the back button. Therefore I assume the current behavior is the intended one.
推荐答案
我正在寻找的是一种将 NavigationController 视图堆栈上的最新 ViewController 替换为一个的方法
what I'm looking for is a way to replace the newest ViewController on the NavigationController view stack by the one
setViewControllers:animated:
让您可以随意构建堆栈.
setViewControllers:animated:
lets you construct the stack however you like.
这篇关于使用 UINavigationController 进行内存管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!