Newbie here programming my first app (having made several tutorial apps). I am using a view controller called ‘RootViewController’ as a navigation controller. I have successfully pushed another view controller on top of this called ‘ClientListViewController’ using the command:
[self.navigationController pushViewController:clientListViewController animated:YES];
I am now in the ClientListViewController and trying to push another view controller onto the stack called ‘AddClientViewController’. I would like to make this a modal view controller in the form of a UIModalPresentationFormSheet. I am trying to use a variation of the command above to push the new view controller but i don’t know how to replace the ‘self’. I have tried:
[RootViewController.navigationController pushViewController:AddClientViewController animated:YES];
and…
[[RootViewController navigationController] pushViewController:AddClientViewController animated:YES];
as well as each of these combinations using small ‘R’s for the word Root. Still no luck.
For clarity, I have used the following code at the top of my implementation file.
#import "AddClientViewController.h"
Am I approaching this in the right way, or should I be using a brand new navigation controller to add it to?
Any pointers greatly received.
Many thanks
Every
UIViewControllerhas a property namednavigationController. This property refers to the nearest enclosingUINavigationController, if there is one. So you can just sayself.navigationControllerin yourClientListViewController.In iOS, we normally capitalize class names. So it sounds like
AddClientViewControlleris a class name. You need to have an instance of that class to push it on the navigation controller’s stack. Something like this:You might need to use a different init method or set some properties of
addClientVCbefore pushing it; that depends on your implementation ofAddClientViewController.If you want to present it modally, you don’t push it on the navigation controller’s stack. Instead you do it this way: