Call storyboard scene programmatically (without needing segue)? Call storyboard scene programmatically (without needing segue)? xcode xcode

Call storyboard scene programmatically (without needing segue)?


Yes you can. Do something like this to get access to the VC, then just Modal Push it:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];MyNewViewController *myVC = (MyNewViewController *)[storyboard instantiateViewControllerWithIdentifier:@"myViewCont"];


Note: the method presentModalViewController:animated is deprecated in iOS 6.

The new code should read:

NSString * storyboardName = @"MainStoryboard_iPhone";NSString * viewControllerID = @"ViewID";UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];MyViewController * controller = (MyViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];[self presentViewController:controller animated:YES completion:nil];


In the storyboard give your view controller an identifier (under the Attributes Inspector) then use the following code to bring that view forward.

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"STORYBOARDNAME" bundle:nil];UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"VIEWCONTROLLERIDENTIFIER"];[self presentModalViewController:vc animated:YES];