Last Updated: December 23, 2016
· mystcolor
Avatar 400

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.

Say Thanks

3 Responses
Add your response

Anonymous bigger normal

I see you retrieve a MySignupViewContnroller instance:

MySignupViewController *controller = [navController viewControllers][0];

But nowhere in your code that uses it?

over 1 year ago ·
Avatar 400

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 ·
Img 3034

Could a segue be performed in the absence of a storyboard?

11 months ago ·