且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

UINavigationController 上的确认返回按钮

更新时间:2022-12-02 18:46:54

很遗憾,这种方式无法拦截后退按钮.最接近的传真是使用您自己的 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.