Sunday 21 September 2014

Best way to modular code using multiple Storyboards in iOS app development

In my earlier post  Best way to Avoid merge conflicts with Storyboards I have made clear why to use multiple storyboards in your iOS app.


Xcode creates only single storyboard with name “Main.storyboard” at the time of creating new project. Lets see below image



Xcode Default Storyboard



Xcode is smart IDE tool its provides option to create another storyboard. how? as simple as creating new file. Under File menu choose New and follow below image steps.

Easy way to use multiple storyboards in iOS app development

Next save it with proper name. Finally you can see two storyboards in the same app.  see below image for better idea.

Managing Multiple storyboards in Xcode objective-c


Next Problem is loading another storyboard in iOS application.  But you can not connect a scene and or segue from one storyboard to another storyboard. Don’t worry we have another solution for working with multiple storyboards in iOS app. We can load another storyboard using little bit coding on an IBAction method and or a selector.

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main” bundle:nil];
UIViewController* myStoryBoardInitialViewController = [storyboard instantiateInitialViewController];

[self.navigationController pushViewController:myStoryBoardInitialViewController animated:YES];


You can use another method to load a scene/ View-controller  using identifier. If you given a identifier to a scene.
Loading scene using identifier is very similar to old way where we were using XIB name to navigate from one View-controller to another View-controller.

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main” bundle:nil];
UIViewController* myStoryViewController = [storyboard instantiateViewControllerWithIdentifier:@“sceneIdentfier”];

[self.navigationController pushViewController: myStoryViewController animated:YES];



Using above code you can load UI from multiple storyboards.

If you have some other Best way to use multiple storyboards in iOS app development please share with me in comments section.





No comments:

Post a Comment