深入理解UINavigationController
我试图更好地理解使用 UINavigationController 创建复杂的导航。请,如果我的任何假设是错误的(这是很有可能的),请告诉我。
据我所知, UINavigationController 似乎是专门为实现一种导航而设计的,其中推送新控制器以“线性”方式提供更深入的数据细节。您可以通过“按下”或返回“弹出”控制器来进一步导航。
然而,通常应用程序在每个视图中都有一种方法可以转到另一个视图,该视图不必是父视图,并且可以位于堆栈的先前级别(或者根本不存在)。此类应用程序往往让用户去任何他想去的地方,这似乎与 UINavigationController 的工作方式相冲突。
对我来说,很明显,如果我开始在没有控制的情况下推动控制器,我就会遇到内存问题。
例如,我如何才能转到堆栈中下两层的视图(例如,“主页”按钮的作用)?我是否应该将一些控制器/视图保存为单例变量中的初始值,以便更好地访问并避免内存问题?
I'm trying to get a better understanding of creating complex navigations with the UINavigationController. Please, If I'm wrong in any assumption (which is so possible) just let me know.
As far as I see, it seems that UINavigationController is specifically designed to achieve a kind of navigation where pushing a new controller provides a more in-depth detail of data in a "linear" way. You can go further in the navigation by "pushing" or back "popping" the controller.
However, it's usual that the application has in every view a way to go to another view which doesn't have to be the parent and can be in previous levels of the stack (or simply doesn't exists yet). Such applications tend to let the user go anywhere he wants, which seems to conflict with the way UINavigationController works.
It seems obvious to me that if I start to push controllers without control I'll have memory problems.
How can I, for example, go to a view which is two levels down in the stack (for example, what a "Home" button would do)?. Should I save some controllers/views as the initial in a singleton variable for better access and avoid memory problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
popToRootViewControllerAnimated:
返回根目录,或使用popToViewController:animated:
弹出回任意先前的视图控制器。您还可以使用 setViewControllers:animated: 直接设置整个视图控制器堆栈。但是,请务必小心,不要让您的用户感到困惑。
You can use
popToRootViewControllerAnimated:
to get back to the root, orpopToViewController:animated:
to pop back to an arbitrary previous view controller. You can also usesetViewControllers:animated:
to directly set the entire stack of view controllers.Do be careful not to confuse your users, however.