如何在从 UINavigationController 弹出 UIViewController 之前显示警报
我有一个 UINavigationController 正在管理多个 UIViewController。当位于视图控制器层次结构的顶部时,当按下返回时,我想显示一个 UIAlertView 来询问用户是否确定要返回。检查视图是否弹出的最佳方法是什么?
I have A UINavigationController which is managing multiple UIViewControllers. When at the top of the view controller hierachy, and when back is pressed, I want to show a UIAlertView to ask the user if they are sure that they want to go back. What is the best way to check if the view is popped?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为后退按钮没有具体的消息。
但您可以尝试子类化UINavigationController,然后重写方法popViewControllerAnimated:。 (我还没有尝试过。)
另一种选择是创建 UIBarButtonItem 类型的自定义后退按钮,并为此按钮添加目标和操作。
I think there is no specific message for the back button.
But you can try to subclass UINavigationController and then override the method popViewControllerAnimated:. (I haven't tried it.)
Another option is to create a custom back button of the type UIBarButtonItem and add a target and action for this button.
这可以通过子类化 UINavigationController 并覆盖来完成
(BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
{
}
重写 popViewControllerAnimated: 来不及取消弹出。
This can be done by subclassing UINavigationController and overriding
(BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item
{
}
overriding popViewControllerAnimated: is too late to cancel a pop.
我认为唯一有效的方法是截取视图的屏幕截图,剪下按钮,然后将 uibutton 添加到导航控制器栏。然后,将剪下的图像设置为按钮图像,然后使用 uialertview 创建一个操作。将您的类设置为 Uialertviewdelegate,并在用户按下 ok 按钮时弹出视图控制器
I think that the only way that works is taking a screenshot of the view, cutting out the button, and then adding a uibutton to you navigationController bar. Then you set the image that you have cut out to be the buttons image, after that you create an action with just a uialertview. Set your class as Uialertviewdelegate, and pop the viewcontroller when the user presses the ok button using
怎么样使用 UINavigationControllerDelegate-Methods 之类的方法
来检查应该推送的控制器是否属于需要警告的类型。反过来也可以!
What about using the UINavigationControllerDelegate-Methods like
and check if the controller which should get pushed is of that kind that it needs an warning. The other way around would also work!