ios segue on condition

ios, iphone

Solution

Delete the segue from the button to the view controller. Instead, control-drag from the view controller that contains the nextButton to the view controller you want to segue to. Then the performSegueWithIdentifier will run only if it meets the conditions.

Problem

I am trying to perform segue after some condition. I created modal segue in main Storyboard from nextPushed button to next view controller. ``` (IBAction)nextPushed:(id)sender { //Perform check that every field /date/from/to/ choised and exists NSString *fromText = [NSString alloc]; NSString *toText = [NSString alloc]; NSString *pasNumText = [NSString alloc]; NSString *dateText = [NSString alloc]; dateText = self.dateAndTimeLabel.text; fromText = self.fromLabel.text; toText = self.toLabel.text; pasNumText = self.numOfPassengersLabel.text; if (!([fromText isEqual:@"Choice" ]) && !([toText isEqual:@"Choice"] ) && !([pasNumText isEqual:@"Choice"]) && !([dateText isEqual:@"Choice"])) { NSLog(@"All fields choisen"); NSLog(@"Going to next view"); [self performSegueWithIdentifier:@"goToDannie" sender:sender]; } else { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Warning" message:@"Not all fields selected" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; } } ``` It is performing segue even if condition is not true and showing alert in next view.

Original source