Isuru Isuru - 6 months ago 14
iOS Question

Fire a segue conditionally to multiple View Controllers

After struggling for days on firing a segue conditionally, I managed to solve it thanks to Simon's answer here. Please take a moment to have a look or you might not understand what I'm talking about below. I didn't copy paste his answer because he's already explained it nicely over there.

Now I've faced a new question. What if I have multiple View Controllers that I want to segue to from one View Controller?

To explain it further : Say I have one

with 2 buttons. When clicked upon each button, it should segue to their respective View Controller. First button to
and the second button to

The method described in Simon's answer can be used when you segue from one View Controller to another View Controller. Since in that method, you tie the segue to the View Controller itsrlf and not to the button, you have only one segue with an identifier for that particular View Controller. Therefore I cannot distinguish between the button taps separately.

Is there a workaround to solve this problem?

Thank you.


It might be bit premature to say this but I guess you should look into Segue more deeply.

Yes you can perform segure from button. Just control click the button and drag the cursor to view controller you want it SEGUE'd. And from my understanding only condition there is each button tap results a segue to a fixed view. There is no condition there.

Also, you can push the navigation controller manually by

YourViewController *destViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"YourDestinationViewId"];
[self.navigationController pushViewController:destViewController animated:YES];


prepareForSegue is too late to stop a segue from proceeding. Yes you can create multiple segues from your view to other view controllers. And in this case you have to do so. Don't reate a segue from button, just define a IBACtion on the button click you can do the validation from there,

if(validationSuccess) {
     [self performSegueWithIdentifier:@"segue1" sender:self];

if you are using ios6

 - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender 

return YES on validation success and NO on failure to stop it from proceeding.