如何管理潜在的无限推动视图控制器到导航控制器堆栈? iOS版 [英] How can I manage the potential endless pushing of view controllers onto the navigation controller stack? iOS

查看:64
本文介绍了如何管理潜在的无限推动视图控制器到导航控制器堆栈? iOS版的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由UINavigationController组成的应用程序,可以从3个不同的选项卡中推送ViewControllers。

I have an app that is made up of a UINavigationController that pushes ViewControllers from 3 different tabs.

我预见到的问题是当前结构允许用户无休止地将VC添加到堆栈中。

The trouble I am foreseeing is that current structure allows the user to endlessly add VC's onto the stack.

我有一个名为pharmaceuticals的标签,另一个叫做病原体。如果你在药物中钻得足够远,你可以得到它有效的病原体清单,用户可以选择一种病原体来查看它的更多信息。这导致应用程序推动新的病原体VC。

I have a tab called pharmaceuticals and another called pathogens. If you drill down far enough in pharmaceuticals you get to a list of the pathogens it is effective against and the user can select a pathogen to see more information about it. This causes the app to push a new pathogenVC.

现在,用户可以深入查看病原体易受影响的药品清单并选择它,这会在药品标签中产生新的VC。

Now the user can drill down to the list of pharmaceuticals the pathogen is susceptible to and select it, which cause a new VC in the pharmaceuticals tab.

依此类推...

每次内存占用量增加1.5Mb。

each time there is an additional 1.5Mb added to the memory footprint.

我怎样才能最好地管理这个?

How can I best manage this?

推荐答案

你应该关注<强大>减少内存占用通过释放资源,您可以轻松地重新创建,而不是试图阻止用户将100个视图控制器推入堆栈。 Apple也没有这样做。

You should focus on minimizing your memory footprint by releasing resources you can easily re-create instead of trying to stop the user from pushing 100 view controllers onto your stack. Apple doesn't do that either.

打开iTunes Store应用程序并搜索Hugh Laurie,选择专辑Let Them Talk,然后选择Hugh Laurie>,然后选择让他们说,然后休·劳瑞>等等。你可以继续前进和前进。当用户长时间执行此操作时,应用程序可能会耗尽内存并崩溃。

Open the 'iTunes Store' app and search for "Hugh Laurie", select the album "Let Them Talk", then on "Hugh Laurie >", then on "Let Them Talk", then on "Hugh Laurie >" and so on. You can keep going and going and going. When the user does this for a very long time, the app will probably run out of memory and crash.

如果你试图在你的丰田皮卡上加载20吨砖块,它可能会像空的Capri Sun包一样被粉碎。这是故意破坏行为,恕我直言,如果用户强行尝试超载,应用可以终止。

If you try to load 20 tons of bricks onto your Toyota Pickup, it will probably be crushed like an empty Capri Sun packet. This is intentional destructive behavior and IMHO it is OK for the app to terminate if the user forcefully tries to overload it.

然而,你可以使这一点几乎无法到达因此,通过在屏幕外视图控制器中释放内存,这种情况不太可能发生。实施 didReceiveMemoryWarning (例如:如何实施didReceiveMemoryWarning?)发布可以从磁盘或网络轻松重新创建的内容(图像,核心数据对象等)。这样,您可以降低内存占用率,如果用户手上有几个小时,用户只能推动视图控制器,那么用户只能让应用程序崩溃。哪个会很难过。

However, you can make this point almost unreachable and thus this scenario very unlikely by releasing memory in your off-screen view controllers. Implement didReceiveMemoryWarning (example: How to implement didReceiveMemoryWarning?) to release things you can easily re-create from disk or the network (images, Core Data objects etc). That way, you can bring your memory footprint way down and your users will only be able to make your app crash if they have several hours on their hands and nothing better to do than to push view controllers. Which would be sad.

这篇关于如何管理潜在的无限推动视图控制器到导航控制器堆栈? iOS版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆