0

If the third nested 'IF' doesn't pass I would like the segue not to run. How can I do that?

- (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;
            }
        }
    }
}
RoboChris
  • 387
  • 1
  • 5
  • 18

2 Answers2

1

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

This method is only Notifies the view controller that a segue is about to be performed.You can not prevent segue.The default implementation of this method does nothing. Subclasses override this method and use it to configure the new view controller prior to it being displayed.

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

check with this May be it will help

To stop segue and show alert

Community
  • 1
  • 1
Bhoomi
  • 81
  • 4
0

You should override shouldPerformSegueWithIdentifier on your UIViewController and put your logic there. You cannot cancel a segue inside prepareForSegue. Take a look at the UIViewController reference for more details.

spassas
  • 4,778
  • 2
  • 31
  • 39