如果嵌套的IF没有通过,如何取消prepareForSegue?

时间:2015-12-09 17:53:39

标签: objective-c if-statement uiviewcontroller io segue

如果第三个嵌套的'IF'没有通过,我希望segue不要运行。我怎么能这样做?

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([segue.identifier isEqualToString:@"showStudentMainPage"]) {

        if (![self.studentEmailField.text isEqualToString:@""] && ![self.studentMDCID.text isEqualToString:@""]) {

            if ([self.data checkStudentEmail:self.studentEmailField.text checkStudentID:self.studentMDCID.text]) {

                StudentMainPageViewController *dest = [segue destinationViewController];

                dest.rowInDB = self.rowInDBHere;
            }
        }
    }
}

2 个答案:

答案 0 :(得分:1)

(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender。

此方法仅通知视图控制器即将执行segue。您无法阻止segue。此方法的默认实现不执行任何操作。子类重写此方法,并在显示之前使用它来配置新的视图控制器。

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/performSegueWithIdentifier:sender

用这个检查可能会有帮助

To stop segue and show alert

答案 1 :(得分:0)

您应该覆盖shouldPerformSegueWithIdentifier上的UIViewController并将您的逻辑放在那里。你无法取消prepareForSegue内的segue。有关详细信息,请查看UIViewController reference