I am curious to know if i can develop an app having 2 view controllers .I have gone through some links ,but couldn't find a solution if I'm using storyboard.If i already have a rooviewcontroller,how can i remove it and add another view as rootviewcontroller?Any thoughts?
Asked
Active
Viewed 328 times
2

Deepak Bharati
- 280
- 2
- 13

Suraj K Thomas
- 5,773
- 4
- 52
- 64
-
If there are two view controllers, then neither is the "root"? – trojanfoe Jan 15 '14 at 13:14
-
sorry i couldn't get u – Suraj K Thomas Jan 15 '14 at 13:16
-
Doesn't matter - it makes more sense now you've edited your question. – trojanfoe Jan 15 '14 at 13:17
-
k.im using storyboard.any ideas – Suraj K Thomas Jan 15 '14 at 13:18
-
1Yes, you can do so. Just check my answer. – Deepak Bharati Jan 15 '14 at 14:57
2 Answers
3
You can do so. You just have to add the code below to the place/action where you want to change the rootViewController.
//First dismiss your currently loaded ViewController
[self dismissViewControllerAnimated:YES completion:nil];
//Get the keyWindow of the app
UIWindow *window = [[UIApplication sharedApplication]keyWindow];
NSString *identifier = @"Your_Identifier_Name_For_ViewController";// this is the identifier name(Storyboard ID)
// of the AnotherRootViewController
// which you have to set in your Storyboard
// as shown in the figure.
//Now create an object of the AnotherRootViewController
AnotherRootViewController *newRootViewController = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
//Finally set your newRootViewController
[window setRootViewController:newRootViewController];
And make setting of AnotherRootViewController to Storyboard as shown in figure:
Let me know if it satisfy your requirement.

Deepak Bharati
- 280
- 2
- 13
1
At a time there is only one rootviewController in app,
you can replace directly using following,
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
YourVC *rootViewController = [storyboard instantiateViewControllerWithIdentifier:@"YourVC"];
self.window.rootViewController = rootViewController;
in appDelegate Method,

Toseef Khilji
- 17,192
- 12
- 80
- 121