Delete the current segue.
Attach the segue from the origin view controller to the destination (and then name it).
Now, your button press method should look something like this:
Objective-C:
- (IBAction)validateLogin:(id)sender {
// validate login
if (validLogin) {
[self performSegueWithIdentifier:@"mySegue" sender:sender];
}
}
Swift:
@IBAction func validateLogin(sender: UIButton) {
// validate login
if validLogin {
self.performSegueWithIdentifier("mySegue", sender:sender)
}
}
The key here is that the origin view controller should be the one you’re dragging from to create the segue, not the button or any other UI element.
Personally, I hook ALL of my segues up this way, even the ones that should trigger on simple button pushes without any validation or logic behind them. It’s easy enough to call it from the button’s method.
And, I usually declare all of my segue names as constant strings somewhere in the project.