I need some help on how to create a Navigation Controller that loads its Root View Controller to a Main View Controller. Then, I want to have that Navigation Controller two selector buttons (leftBarButtonItem and rightBarButtonItem) that will take the user to 2 custom View Controllers (AboutViewController and SettingsViewController).
I was able to do this successfully but instead, I created the 2 view controllers inside the MainWindow.xib with all codes inside AppDelegate.h and AppDelegate.m. This is obviously not a good practice especially when you have a lot of custom view controllers.
Thanks.
You are right that it isn’t good practice to create your view controllers in the AppDelegate. Instead, you should create a separate ViewController for each view. In the implementation file for your rootViewController, create methods to push the separate view controllers that you want to show when the buttons are pressed. Something like this would work:
Then, include those methods in the selector field for your buttons. Like this:
This should take care of pushing your view. The navigationController will automatically show a button to ‘go back’.
In the AppDelegate, you would create the navigationController and tell it what view will be the rootViewController, like this:
Hope this helps!