Create and Perform a Storyboard Segue programatically
You might wanted to create and perform custom UIStoryboardSegue in code.
Here's an example on how we use an opensource library BlurryModalSegue to present a different view controller that's not in the main Storyboard.
- (void)presentSignupViewController {
// Storyboard ID
UIStoryboard *modalStoryboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
UINavigationController *navController = [modalStoryboard instantiateViewControllerWithIdentifier:@"MySignupViewController"];
MySignupViewController *controller = [navController viewControllers][0];
// Configure your custom view controller, e.g. setting delegate
controller.delegate = self;
// Show VC
navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
BlurryModalSegue *segue = [[BlurryModalSegue alloc] initWithIdentifier:@"SignupScene" source:self destination:navController];
[segue perform];
}
That's it :) There're also many more very useful open source libraries here.
Written by James Tang
Related protips
3 Responses
I see you retrieve a MySignupViewContnroller instance:
MySignupViewController *controller = [navController viewControllers][0];
But nowhere in your code that uses it?
over 1 year ago
·
Hi @gk, thanks for noting. That was a chance to configure your view controller such as passing a variable to your custom view controller. I've updated the code to make it more clear. Thanks!
over 1 year ago
·
Could a segue be performed in the absence of a storyboard?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ios
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#