Navigate between multiple storyboards in iOS App - ios

I wanted to have separate storyboard files for every UIViewcontrollers in my iOS app.
So how can we assign different storyboards for each controllers? Also how do we do navigation between those?
This I am doing to avoid svn conflicts while so many people working on UI.

get a reference to the storyboard...
UIStoryboard *someStoryboard = [UIStoryboard storyboardWithName:#"NameOfYourStoryboard" bundle:nil];
then instantiate either the initial viewcontroller from that storyboard...
UIViewController *initialViewController = [someStoryboard instantiateInitialViewController];
or some other viewcontroller identified by it's storyboard identifier...
UIViewController *someOtherViewControllerFromTheStoryboard = [someStoryboard instantiateViewControllerWithIdentifier:#"SomeViewControllersStoryboardIdentifier"];
after that you can simply push (within a navigation controller) or present the new viewcontroller.
since iOS 9.0 you can even connect storyboards via storyboard references in the storyboard itself:
https://developer.apple.com/library/prerelease/ios/recipes/xcode_help-IB_storyboard/Chapters/AddSBReference.html

Keeping different storyboards for different modules is good approach. You can achieve the navigation between storyboards as follows:-
Suppose you are in A view controller and want to push another view controller named FabIdeaDetailViewController which is present in storyboard named FabIdeas:-
FabIdeaDetailViewController *horizontalListController = (FabIdeaDetailViewController*)[UIViewController instantiateViewControllerWithIdentifier:#"FabIdeaDetailViewController" fromStoryboard:#"FabIdeas"];
[self.navigationController pushViewController:horizontalListController animated:YES];
Now for pushing another view controller named WishlistViewController which is present in storyboard named Wishlist:-
UIViewController *WishlistViewController = [UIViewController instantiateViewControllerWithIdentifier:#"WishlistViewController" fromStoryboard:#"Wishlist"];
[self.navigationController pushViewController:WishlistViewController animated:YES];

Related

access multiple viewControllers from the main viewControllers programmatically in a storyboard

first part of my question is basic understanding.
I believe the other viewControllers in the storyboard are in a "Non instantiated" form when application is launched, and are launched when they are sequed, please confirm?
Second part how do I programmatically instantiate a sibling UIViewController within the storyboard and optionally create a seque to it. I've found some code from Objective-C (pasting below) but looking for a solution in SWIFT.
MyViewController *myVC = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"MyViewController"];
Your first statement is true to a certain extent. Any controller connected to one that does get instantiated by a relationship segue or an embed segue will also be instantiated (like all the children of a tab bar controller). In your code snippet, you don't need to use storyboardWithName: if you're calling that method from a controller that was created in the same storyboard; you can just use self.storyboard.
var myVC = self.storyboard.instantiateViewControllerWithIdentifier("MyViewController")

Xcode is very laggy with lots of View Controllers

My project contains over 60 View Controllers and Xcode is very laggy when loading the storyboard.
How can I resolve this without switching to xibs? I am using Xcode 5.1 and iOS 7.x
Problem
Putting all of your ViewControllers in one Storyboard will significantly slow down Xcode (which renders XML to show your ViewControllers) if the number of the ViewControllers is above 10. Storyboard is not the place to put all of your views, because as its name suggests a board of a specific story.
Solution
Make multiple Storyboards with 5 or 6 ViewControllers each, where you can avoid rendering hell of multiple ViewControllers. You can divide your Application on different boards named by group functionality like LoginStoryboard, UserProfileStoryboard, etc.
You can instantiate a storyboard and present a specific controller by the code below:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Your Storyboard Name" bundle:nil];
UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:#"Your Controller ID"];
[self presentViewController:viewController animated:true completion:nil];
Keep views in more than one storyboard. It's not the problem if not every controllers are connected with segues. There is no good way to keep a large number of views in a storyboard, in addition to working on a better computer.

Using storyboard only for certain view controllers

I have done a separate project using storyboard.
I need to integrate with an existing big project which doesn't use storyboard.
Is it possible to use storyboard partly (only for some view controllers)? If so how ?
Sure. You can instantiate separate view controllers from storyboard:
Getting a Storyboard Object
+ storyboardWithName:bundle:
Instantiating Storyboard View Controllers
– instantiateInitialViewController
– instantiateViewControllerWithIdentifier:
For ex:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
YourViewController *yourVC = [storyboard instantiateViewControllerWithIdentifier:#"yourViewControllerIdentifier"];
Yes. It is possible. Any view controllers that aren't on the storyboard are presented in exactly the same way they were in the old projected, by instantiating, setting properties (if need be), and pushing.

Move between multiple storyboards by replacing the windows root controller

To move between VCs on a single storyboard, I use the first custom segue from the post :
bidirectional storyboard travel without stacking This replaces the window's root view controller with the destination view controller, so the VCs do not stack and cause memory allocation issues.
I need to use multiple storyboards and so I am after a method of moving to a second storyboard that replaces the windows root controller with the initial VC of the new storyboard (I.e in a similar way to the custom segue I have used throughout the rest of the project.)
The solution should ideally work for IOS6 & IOS7 (the pseudo-segue method has been updated to IOS7 only)
Any ideas?
You can't do this with a segue. Segues can only be made between controllers in the same storyboard. The only way to do this, is in code by instantiating that first controller, and setting it as the window's root view controller.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"SomeOtherStoryboard" bundle:nil];
NewController *new = [sb instantiateInitialViewController];
self.view.window.rootViewController = new;

how to xib view controller push a storyboard view controller

I am developing an app, and in the process, I have to arrange view controllers process like storyboard->xib->storyboard because i have to use xib due to AR SDK. Could any friendly guy tell me how to xib->storyboard? Thanks a lot!!
MyViewController* *myViewController =
[[UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:NULL]
instantiateViewControllerWithIdentifier:#"myController"];
using instantiateViewControllerWithIdentifier or instantiateInitialViewController to get storyboard view controller and you can call transitionFromViewcontroller:toViewController:duration:option:animations:completion api to bring up the view or you can just present view.

Resources