0

Problem

I have an app with a UITabBarController and four different tabs. Three of these tabs are tables which you can click on each row and it would take you to another view.

Question

How would I implement that in terms of navigation? Should I create a UITabBarController with Navigation Controllers as tabs (as shown in image 1) or with View Controllers as tabs (as shown in image 2) with each View Controller having its own Navigation Controller property?

Image 1:

Image 1

Image 2:

Image 2

I tried both but its not working well and its confusing. I'd like to know which is more appropriate so I can focus on that method and then see why it's not working.

darksky
  • 20,411
  • 61
  • 165
  • 254

1 Answers1

3

The first method you propose is the only method. View controllers have a navigationController property, but it will only return something if your view controller is currently contained within a parent navigation controller.

So to be clear: you should have a UITabBarController which contains your navigation controllers, one navigation controller for each tab that you want to have a navigation hierarchy in.

lxt
  • 31,146
  • 5
  • 78
  • 83
  • So if the VC is not contained within a parent nav controller it won't work? So in general, if I need a nav controller for a VC, then it should be declared in the App Delegate? – darksky Jul 04 '11 at 07:03
  • If the VC isn't contained within a parent nav controller the `navigationController` property will return nil. Your VC will obviously still display, but you won't be able to transition to another view controller via the navigation stack because the navigation controller won't exist. You can certainly create your navigation controllers in your app delegate, but if you're using interface builder you can automate this process somewhat. – lxt Jul 04 '11 at 08:49