Using storyboard only for certain view controllers - ios

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.

Related

Navigate between multiple storyboards in iOS App

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];

Difference between instantiateViewControllerWithIdentifier and initWithNibName?

What is the difference between instantiateViewControllerWithIdentifier and initWithNibName, other than former is from storyboard and later is not?
UIStoryboard *signupStory = [UIStoryboard storyboardWithName:#"SignupStory" bundle:[NSBundle mainBundle]];
SignupLoginViewController *signUpVC = [signupStory instantiateViewControllerWithIdentifier:#"SignupVC"];
and
SignupLoginViewController *signUpVC = [[SignupLoginViewController alloc] initWithNibName:#"SignupLoginViewController" bundle:[NSBundle mainBundle]];
If you've created your UI using storyboards, you'll want to call instantiateViewControllerWithIdentifier. Here, the identifier is not part of the view controller itself but is only used by the storyboard to locate the view controller. The storyboard will handle initialization and eventually call initWithCoder, which is why you need to override this when creating subclassed view controllers.
On the other hand, if your UI resides in a pure .xib file - developers generally use initWithNibName. It does, technically, break encapsulation and there are other ways to do it, but you'll see this used most often as it's the designated initializer for the class.

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.

iOS Change Story Board

My iPad App has two storyBoards - FirstStoryBoard and SecondStoryBoard
I have a single ViewController
I notice that Under Project > Targets > Summary there is an option for specifying the MainStoryBoard and if I change this setting the correct story board loads correctly.
The Question - How can I change the behavior so that I can change between the first and second story board at run time. In other words I want to
First, create storyboard instance:
UIStoryboard *board = [UIStoryboard storyboardWithName:#"MyStoryboard" bundle:nil];
and then get first view controller from it:
UIViewController *vc = [board instantiateInitialViewController];
add as child view controller:
[self addChildViewController:vc];
or maybe (if you are in AppDelegate.m / application:didFinishLaunchingWithOptions: method)
self.window.rootViewController = vc;
The Question - How can I change the behavior so that I can change
between the first and second story board at run time.
You can't switch the value of the Main Storyboard setting (specified by the UIMainStoryBoard key in your Info.plist) at runtime, so do the next best thing: use a common storyboard or nib file that contains very little, and then instantiate the storyboard that you want using the UIStoryboard class. For example, you could use a simple nib file to create your app delegate, and have the app delegate's -application:willFinishLaunchingWithOptions: load first view controller from the storyboard of your choice.

Resources