确认UINavigationController上的后退按钮 [英] Confirm back button on UINavigationController

查看:97
本文介绍了确认UINavigationController上的后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UINavigationController 我的应用程序的故事板。我想在默认的后退按钮中添加一个确认对话框,这样用户就不会意外注销。有办法做到这一点吗?我发现,当它由 UINavigationController 自动创建时,我不能简单地访问后退按钮。

I am using the storyboard for my app which is using UINavigationController. I would like to add a confirmation dialog to the default back button so the user does not log out accidentally. Is there some way to do this? I have found that I cannot simply access the back button when it has be automatically created by the UINavigationController.

任何想法?

推荐答案

不幸的是,你不能以这种方式拦截后退按钮。最接近的传真是使用您自己的 UIBarButtonItem 设置为 navigationItem.leftBarButtonItem 并设置操作以显示您的警报等我有一个图形设计师创建看起来像标准后退按钮的按钮图像。

Unfortunately, you can't intercept the back button in this way. The closest facsimile is to use your own UIBarButtonItem set to the navigationItem.leftBarButtonItem and set an action to display your alert etc. I had a graphic designer create button images that look like the standard back button.

另外,我需要拦截后退按钮的原因不同。我劝你重新考虑这个设计选择。如果您要呈现用户可以进行更改的视图,并且您希望他们可以选择保存或取消IMHO,则最好使用保存和取消按钮与带警报的后退按钮。警报通常很烦人。或者,明确表示用户所做的更改是在用户进行更改时提交的。那么这个问题没有实际意义。

As an aside, I needed to intercept the back button for a different reason. I urge you to reconsider this design choice. If you are presenting a view where users can make changes and you want them to have the choice to save or cancel IMHO it's better to use 'Save' and 'Cancel' buttons vs a back button with an alert. Alerts are generally annoying. Alternatively, make it clear that the changes your users are making are committed at the time they make them. Then the issue is moot.

这篇关于确认UINavigationController上的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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