Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

PBG4 Dude

macrumors 601
Original poster
Jul 6, 2007
4,445
4,829
I want to use the same view either by tapping a tab on the tab bar, or if the view is navigated to from a different area of the program.

My problem is, if I use the tab bar navigation, I don't have the navigation controller on top of the view. If I navigate to the view from a different section of the program, then it does have a navigation controller and everything works.

Is there a way to programmatically generate a navigation bar when I tap the Tab Bar Item.

I tried subclassing UITabBarController, then setting self.tabbar.delegate = self; in viewDidLoad, but this causes an insta-crash.

I haven't run into issues before setting self as a delegate so I don't know why it is happening with the tab bar?

Alternatively, is there a way to add the navigation controller when the viewController is instantiated if it can determine it is not part of a navigation controller?

I am using Storyboards if that makes any difference.
 
Last edited:
You can check in the viewcontroller if it is inside a navigationcontroller or not.

Code:
if (self.navigationController) {
    NSLog(@"I am inside a navigationController");
}

You can of course add a navigationBar of your own programatically but I always find it easier to add a navigation controller in IB and then hide my own nav bar when inside a navigationcontroller.
 
dantastic,

Thanks for your reply.

I found a similar sounding solution, that so far hasn't required any code.

I embedded my view into a navigation controller in my storyboard. Then I pointed to the navigation controller from the tab bar, which gave me the navigation bar I needed.

In the other part of my program where I already have a navigation controller in place, my segue points directly to the view, and not to the navigation controller.

(Below solution found here. )

It looks something like this picture, just the segue starting points are different in my program:

1iHG2.png
 
Last edited:
  • Like
Reactions: Krevnik
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.