Resolved Use View With Tab Bar & With Navigation Bar

Discussion in 'iOS Programming' started by PBG4 Dude, Mar 25, 2014.

  1. PBG4 Dude, Mar 25, 2014
    Last edited: Apr 8, 2014

    PBG4 Dude macrumors 68000

    PBG4 Dude

    Joined:
    Jul 6, 2007
    #1
    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.
     
  2. dantastic macrumors 6502

    dantastic

    Joined:
    Jan 21, 2011
    #2
    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.
     
  3. PBG4 Dude, Mar 26, 2014
    Last edited: Mar 26, 2014

    PBG4 Dude thread starter macrumors 68000

    PBG4 Dude

    Joined:
    Jul 6, 2007
    #3
    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:

    [​IMG]
     

Share This Page