如何在从 UINavigationController 弹出 UIViewController 之前显示警报

发布于 2024-11-27 21:08:45 字数 132 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烛影斜 2024-12-04 21:08:45

我认为后退按钮没有具体的消息。
但您可以尝试子类化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.

紫瑟鸿黎 2024-12-04 21:08:45

这可以通过子类化 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.

清晨说晚安 2024-12-04 21:08:45

我认为唯一有效的方法是截取视图的屏幕截图,剪下按钮,然后将 uibutton 添加到导航控制器栏。然后,将剪下的图像设置为按钮图像,然后使用 uialertview 创建一个操作。将您的类设置为 Uialertviewdelegate,并在用户按下 ok 按钮时弹出视图控制器

- (void)alertView:(UIAlertView *)actionSheet     clickedButtonAtIndex: (NSInteger)buttonIndex {
   if (buttonIndex == 0)
    {
       //pop viewcontroller
    }
  }

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

- (void)alertView:(UIAlertView *)actionSheet     clickedButtonAtIndex: (NSInteger)buttonIndex {
   if (buttonIndex == 0)
    {
       //pop viewcontroller
    }
  }
执笔绘流年 2024-12-04 21:08:45

怎么样使用 UINavigationControllerDelegate-Methods 之类的方法

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

来检查应该推送的控制器是否属于需要警告的类型。反过来也可以!

What about using the UINavigationControllerDelegate-Methods like

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文