Last Updated: December 23, 2016
· mystcolor

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.

3 Responses
Add your response

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 ·