I was wondering if anyone could explain the following block of code because I don't really understand it.
self.viewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
self.navigationController = [[ UINavigationController alloc ] initWithRootViewController:self.viewController ];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
Then when you want to present a new vc you can do this:
OtherViewController *ovc = [[ OtherViewController alloc ] initWithNibName:@"OtherViewController" bundle:nil ];
[ self.navigationController pushViewController:ovc animated:YES ];
To go back do this:
[ self.navigationController popViewControllerAnimated:YES ];
A navigation controller needs a "root" view controller, which is the bottom view controller in the stack of view controllers it manages.
Line 1 creates a view controller of class "RootViewController" (which must be a custom view controller class.) It loads the view controller's views from a nibfile of the same name. This is similar to using instantiateViewControllerWithIdentifier to load a view controller from a storyboard, except that you have to specify the class of view controller you're creating, and the nibfile you're loading the
Line 2 creates a navigation controller with the newly created "RootViewController" as it's root view controller
Line 3 installs the navigation controller as the root view controller of the application window.
Line 4 makes the app window the active window.