UINavigationController 上的确认返回按钮 [英] Confirm back button on UINavigationController

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

问题描述

我正在为使用 UINavigationController 的应用程序使用 storyboard.我想在默认的后退按钮中添加一个确认对话框,这样用户就不会意外注销.有没有办法做到这一点?我发现当 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.

顺便说一句,出于不同的原因,我需要拦截后退按钮.我敦促您重新考虑这种设计选择.如果您正在呈现用户可以进行更改的视图,并且您希望他们可以选择保存或取消恕我直言,最好使用保存"和取消"按钮而不是带有警报的后退按钮.警报通常很烦人.或者,明确说明您的用户所做的更改是在他们进行更改时提交的.那么这个问题就没有实际意义了.

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天全站免登陆