iPhone 导航控制器 - 重用视图的最佳实践

发布于 2024-10-01 12:29:14 字数 504 浏览 2 评论 0原文

你好 我在我的应用程序中经常使用导航控制器,但我的应用程序开始遇到视图反复调用相同视图并将它们推送到导航控制器堆栈上而不是重用堆栈上现有视图的问题。

例如,我有一个在我的应用程序中的各个位置调用的地图视图。

我真的应该检查导航控制器堆栈并找到我已经推送的地图视图并将其移至堆栈顶部。

相反,我创建了一个新的并将其推到顶部。

随着我的应用程序变得越来越复杂,我肯定会遇到内存问题,并且用户会厌倦点击后退按钮进入主菜单。

任何人都有在导航控制器堆栈中查找视图的好例子。

我该怎么做呢?

我是否需要在 App Delegate 中保留指向我的地图视图的指针?

如果有办法在堆栈中快速找到视图,或者我是否需要将索引/NSDictionary 保存到它们的位置。

我注意到现在编写 Facebook 应用程序的人都遇到了同样的问题。当通知进来时,他们打开应用程序并实例化通知视图并将其推送到堆栈上。一段时间后,您最终会关闭一大堆旧的通知窗口以返回主菜单。 干杯

Hi
I use Navigation controllers a lot in my app but my apps starting to suffer from views calling the same views over and over and pushing them on the nav controller stack rather than reusing existing views on the stack.

For instance I have a map view thats called in various places in my app.

I should really go through the Nav Controller stack and find the mapview I pushed already and move it to the top of the stack.

Instead I create a new one and just push it on the top.

As my app gets more complicated Im sure ill get memory issues and users will get bored hitting the back button to get to the main menu.

Anyone got good example of finding a view in the Nav Controller stack.

How should I do it?

Do I need to keep a pointer to my Map View in App Delegate?

If there a way to find a view quickly in the stack or do I need to keep an index/NSDictionary to their location somewhere.

I noticed that whoever is writing the Facebook app now has the same problem. As notifications come in they open the app and instantiate the Notification view and push it on the stack. After a while you end up closing a whole pile of old notification windows to get back to main menu.
cheers

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

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

发布评论

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

评论(1

2024-10-08 12:29:15

如果您希望将特定的视图控制器放在堆栈顶部(您已经将其压入堆栈),则可以使用以下方法,而不是创建视图控制器。

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

如果您事先知道 viewController 将被推送到堆栈上,您可以使用下面的函数一次推送它们,而不是一次又一次地推送它们。

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

If you want the particular viewcontroller on the top of stack, which you have already pushed on the stack, instead of creating one, you can use the following method.

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

If you know in advance the viewControllers will be pushed on the stack, you can push them at once with the below function, instead of pushing them again and again.

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