ios - 取消 iOS 中的导航栏操作

标签 ios uinavigationbar

我正在开发一个 iOS 应用程序,该应用程序涉及用户填写文本字段和浏览 View 。目前,导航有时使用导航栏,有时通过按钮来处理。我尝试将某些字段设为必填:如果这些字段留空,则会阻止应用程序的进展。这适用于基于按钮的导航,但不适用于导航栏。我的代码如下:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"birthPopBus"]) {
        currentPopoverSegue = (UIStoryboardPopoverSegue *)segue;
        pvc = [segue destinationViewController];
        [pvc setDelegate:self];
    }
    else if([[segue identifier] isEqualToString:@"SecondBusPageSegue"]) {
        //This code breaks the next page

        //Check fields, and create error message (code removed for readability)...

        //If the fields are not filled in, display the alert with generated string.
        if(!(first && last && email && phone && address && zip && ssn && birthFilled)){
            UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Required Fields Missing:"
                message:alertMessageMutable
                delegate:nil
                cancelButtonTitle:@"OK"
                otherButtonTitles:nil];
            [message show];

        }

        //Perform the segue, should only run if all required fields are filled.
        else{     
            [self fillBus1Dictionary];
            NSLog(@"application dictionary: %@", self.application);

            SecBusPage * secondBusPage = segue.destinationViewController;
            secondBusPage.application = self.application;
        }
    }
}

错误消息将会显示,但仅在 View 更改后才会显示。因此,用户进入 SecondBusPage,并收到一条警告,提示“您没有填写字段 X、Y、Z”。这对他们来说非常困惑。有什么办法可以防止导航栏切换 View 吗?

提前致谢!

最佳答案

您可以通过实现条件转场轻松实现这一目标,就像我在下面链接的帖子中的回答中的那样

Conditional Segue Using Storyboard

您无法从prepareForSegue 取消segue。相反,根据条件执行 Segues

关于ios - 取消 iOS 中的导航栏操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18986832/

相关文章:

ios - 在 Objective-C 中定义变量、setter 和 getter

ios - 使用 loadNibNamed 时,为什么我们必须使用 'first' ?我们不想分离源代码的不同实体吗?

swift - 当父 View 带有标题时如何在 SwiftUI 中隐藏导航栏

ios - iOS 6 应用程序的 iOS 7 兼容模式不考虑导航栏的色调颜色?

ios - 推送 UIView 时隐藏 UITabBar

ios - 在 UINavigationBar 左侧的 "back"按钮旁边添加另一个按钮

xcode - iPod 在 iTunes 中恢复 : but now in Xcode: No provisioned iOS device is connected

ios - 从 iOS 中的浮点值手动定位

iphone - 导航 View 的背景图像

ios - UIContextualAction 图标和文本对齐