Reputation: 4313
I have an application that uses the "navigation-based application" template in XCode.
Now I want to change it so that the first view that loads is a regular (custom) UIView, and if the user clicks a particular button, I push the original RootViewController onto the NavigationController.
I understand that somewhere, someone is calling this with my RootViewController:
- (id)initWithRootViewController:(UIViewController *)rootViewController
I want to know how to replace the argument with my new class.
Upvotes: 15
Views: 18415
Reputation: 358
^ These are all ways to do it programmatically. Thats cool. But I use the interface builder and storyboards in Xcode, so this is the easy and fast way to add a new view controller:
Tada! Enjoy your new root view controller without holding your day up with programmatic creation.
Upvotes: 5
Reputation: 11145
if you want to replace the root view controller of your navigation stack you can replace the first object of its view controllers array as -
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[self.navigationController viewControllers]];
NewViewController *nvc = [[NewViewController alloc] init];
[viewControllers replaceObjectAtIndex:0 withObject:nvc];
[self.navigationController setViewControllers:viewControllers];
Upvotes: 23
Reputation: 1019
Look inside the main app delegate .m file and find the method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Inside it will be a line like this
self.window.rootViewController = self.navigationController;
You can instantiate a diffent view controller there and assign it to be the rootViewController
Upvotes: 2