I’ve just updated my Xcode from 4.2 to 4.3.3 and i keep coming across a problem
is it possible to add a navigation controller in a single view application because when i try to embed one into the controller nothing happens. I would like to have two view controllers connected by a button to the second controller and a navigation bar back to the first view controller.
I can’t think of any other way to connect the view controllers please help me
any-ideas.
If you don’t want to add a navigation controller, you could transition between your existing view controllers using
presentViewControllerto go from the first one to the second one, anddismissViewControllerAnimatedto return.Assuming you’re using a NIB (otherwise you’d just use the embed command for the storyboard), if you want to add a navigation controller staying with your NIB, you can alter your app delegate accordingly.
So, you probably have an app delegate that says something like:
Change this to add a navigation controller (you can get rid of the previous reference to your main view controller here):
And then, in your app delegate’s implementation file, you have a
didFinishLaunchingWithOptionsthat probably says something like:You can change that to say:
Having done that, you can now navigate from one NIBs view controller to another’s using
pushViewControllerand return withpopViewControllerAnimated. In yourviewDidLoadyou can also use theself.title = @"My Title";command to control what appears in the view’s navigation bar. You may also want to change the “Top Bar” property in your NIBs to include the navigation bar simulated metric, so that you can layout your screen and have a good sense of what it’s going to look like:Clearly, if you’ve got a non-ARC project, those lines with the alloc/init of the view controllers should also have an
autorelease, too (which will be obvious when you look at your app delegate).