如何处理按下的 backBarButtonItem?
我几乎在所有应用程序中都完成了此操作,但是我在 navigationController 中堆叠了 3 个视图,并且我需要从第三个视图跳转到第一个视图。 据我了解,我只能通过 viewWillDisappear 来做到这一点。但是如果我尝试这个“跳转”,我将从第二个视图中获取 navigationController 面板,该面板带有导致异常/错误的导航按钮。
PS 不要建议我让 leftBarButtonitem 看起来像 backBarButtonItem。这太难了,我不知道在哪里可以找到合适的图像。
I have almost done this in all the application but I have 3 views stacked in navigationController and I need to jump from the third view to the first view.
As I understand I can do this via viewWillDisappear only. But if I try this "jump" I will get the navigationController panel from the second View which with a navigation buttons which cause exceptions/errors.
P.S. Do not advice me to make leftBarButtonitem looking like backBarButtonItem. It is too difficult and I don't know where to find an appropriate image for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,您别无选择,只能提供自己的
UIBarButtonItem
。默认情况下,您不允许中断UINavigationController
的工作方式。也就是说,您无法覆盖后退按钮的行为。您必须提供自定义栏按钮项并将其设置为导航项的左栏按钮项。(顺便说一句,您正在寻找的行为可能表明导航模式不佳。后退按钮几乎应该总是按顺序退出导航层次结构。)
To my knowledge, you have no choice but to provide your own
UIBarButtonItem
. You are not permitted from interrupting howUINavigationController
works by default. That is, you cannot override the behavior of the back button. You must provide a custom bar button item and set it as the navigation item's left bar button item.(As a side note, the sort of behavior you're looking for may be an indication of a poor navigation pattern. Back buttons should almost always back out of a navigation hierarchy sequentially.)
假设按照导航顺序,您的视图像顶部一样堆叠 -> 3-> 2-> 1.当您处于此位置时,您可以在应用程序委托中有一个标志,显示按下 backButton 时您将 doublePop,如下所示:(每当第三个视图按您提到的顺序出现时,您就会执行此操作)
在视图 2 中:
希望它有所帮助。
Let's say in navigation order your views stacked like top -> 3 -> 2 -> 1 . When you are in this position you can have a flag in your application delegate that shows you will doublePop when backButton pressed as below: ( You are doing this whenever third view appears in the order you mentioned)
In view 2 :
Hope it helps.