The easiest solution is to create manual segue in story board and use that as seen below.
[self performSegueWithIdentifier:@"loginSuccessSegue" sender:self];
Or
@Fabio: I was trying to get a solution for same kind of use-cases and I almost found a solution.
Use-cases
1. Stop segue transition conditionally
2. Change destination viewController conditionally
Solution:
Use "Custom" segue.
Follow below steps to create Custom segue
1. Create a subclass of UIStoryboardSegue
"MyCustomSegue.h"
@interface MyCustomSegue : UIStoryboardSegue
@end
"MyCustomSegue.m"
Override initWithIdentifier for implementing use-case 1 and 2
If you return nil, segue will be cancelled/no action will be taken
You instantiate your ViewController and set that as a destination.
You can set destination as your old xib file also.. that code is commented, but I ensured that will work.
@implementation MyCustomSegue
- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination{
UIStoryboard *storyBoard= [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:@"testIdentifier"];
// MyViewController* viewController= [[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];
return [super initWithIdentifier:identifier source:source destination:viewController];
}
- You must override "perform".
You can implement use-case 1 here also..
- (void)perform {
// if either source or destination is nil, stop
if (nil == self.sourceViewController || nil == self.destinationViewController) return;
// return; //No Action. Segue will be cancelled
UINavigationController *ctrl = [self.sourceViewController navigationController];
[ctrl
pushViewController:self.destinationViewController
animated:YES];
}
Hope this helps. Plz write if you are not clear.