UINavigationController自定义popViewControllerAnimated方法

问题描述 投票:2回答:2

我制作了一个自定义UINavigationController类,以便可以弹出UIAlertView并说,确定要在单击后退按钮时退出此视图。

我有一个客户,如下所示:

- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
    if([[self.viewControllers lastObject] class] == [weddingSetupController class]){

        UIAlertView *exitAlert = [[UIAlertView alloc] 
                                  initWithTitle:@"Are you sure?" 
                                  message:@"By leaving the setup, all current changes will be lost. The setup can be retsrated later if you decide to leave now. However, it is recomened for your best experience that you complete the setup." 
                                  delegate:self cancelButtonTitle:@"No" 
                                  otherButtonTitles:@"Yes", nil
                                  ];

        [exitAlert show];

        return nil;
    } 
    else {
        return [super popViewControllerAnimated:animated];
    }
}

效果很好,虽然有一个问题,但是当我说“否”时,它会停留在同一视图上,而不是弹出父视图,但导航栏会弹出。因此,我认为视图不会弹出,但栏始终返回其父视图的状态。

iphone objective-c uinavigationcontroller uinavigationbar
2个回答
3
投票

[当您按下导航栏上的后退按钮时,它正在调用:

- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated;

在UINavigationBar中,后者又在导航控制器上调用popViewControllerAnimated。重写此方法(我使用类别,以避免子类化),并采用相同的方法。您的首要目标只是晚了一步。


2
投票

我认为,理想情况下,用户永远不必“保存”任何内容-隐式保存所有内容。因此,如果他们离开安装程序并稍后再回来,他们应该能够从上次中断的地方继续。

但是,如果您仍然想用这种方式,最好在顶部使用“取消”和“完成”按钮的模态视图。现在,我想到了,邮件将要求您使用操作表保存未发送的草稿。

© www.soinside.com 2019 - 2024. All rights reserved.