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.
Related
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];
I'm begin learn iOS and i have a question: when i launch the project, app will load all view controller or just the Initial View Controller in Main.storyboard?
In case, my app have a lots of view controller, e.g 50 VC, i want to check 50 VC be loaded in one time or each VC be loaded when i call e.g like this :
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"myViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
After research and ask some friends, i see in Apple doc:
The main storyboard is defined in the app’s Information property list
file. If a main storyboard is declared in this file, then when your
app launches, iOS performs the following steps:
It instantiates a window for you.
It loads the main storyboard and instantiates its initial view controller.
It assigns the new view controller to the window’s rootViewController property and then makes the window visible on the
screen.
It just load only Initial View Controller set in Main.storyboard. You can set any view controller as initial view controller from storyboard-> select any view controller -> go to utility portion of xCode-> go to attribute inspector-> now check is Initial View Controller.
From Docs :
A UIStoryboard object encapsulates the view controller graph stored in
an Interface Builder storyboard resource file. This view controller
graph represents the view controllers for all or part of your
application’s user interface. Normally, view controllers in a
storyboard are instantiated and created automatically in response to
actions defined within the storyboard itself. However, you can use a
storyboard object to instantiate the initial view controller in a
storyboard file or instantiate other view controllers that you want to
present programmatically.
StoryBoard will load just initial viewController on load of the app. Other view controllers will load on performing segues or manually by following methods.
- instantiateInitialViewController
- instantiateViewControllerWithIdentifier:
Read more at here
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")
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.
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;