1

I have a UINavigationController inside a UITabBarController.

My viewDidLoad from the navigation controller looks like this:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationBar.barTintColor = [UIColor blueColor];
    self.navigationBar.translucent = NO;

    self.navigationBar.topItem.title = @"HOME";
    self.navigationItem.title = @"HOME"; // Neither works

        // create three funky nav bar buttons
    UIBarButtonItem *one = [[UIBarButtonItem alloc]initWithTitle:@"One" style:UIBarButtonItemStylePlain target:self action:@selector(testMethod)];
    UIBarButtonItem *two = [[UIBarButtonItem alloc]initWithTitle:@"Two" style:UIBarButtonItemStylePlain target:self action:@selector(testMethod)];
    UIBarButtonItem *three = [[UIBarButtonItem alloc]initWithTitle:@"Three" style:UIBarButtonItemStylePlain target:self action:@selector(testMethod)];

    // create a spacer
    UIBarButtonItem *space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
    space.width = 30;

    NSArray *buttons = @[one, space, two, space, three];

    self.navigationItem.rightBarButtonItems = buttons;

}

Doing this successfully changes my navigation bar to a blue color, but neither the title or the buttons show up. No matter what method I try, I can't seem to get it to have a title. I don't know if it has to do with it being in a tabviewcontroller or not. Any ideas?

Thanks,

rmaddy
  • 314,917
  • 42
  • 532
  • 579
evenodd
  • 2,026
  • 4
  • 26
  • 38
  • try with `self.title = @"HOME";` Is this code of VC OR NavigationController? – Yogesh Suthar Jul 07 '14 at 04:02
  • Is this the `viewDidLoad` of a view controller in the navigation controller or is this the `viewDidLoad` of a `UINavigationController` subclass? – rmaddy Jul 07 '14 at 04:05
  • @YogeshSuthar that changes the title on the tab bar, not on the uinavigation bar – evenodd Jul 07 '14 at 04:07
  • @rmaddy this is the viewdidload of UINavigationController class which is embedded into tabviewcontroller – evenodd Jul 07 '14 at 04:08
  • 1
    @GabeJacobs That's the problem. You should be doing everything in the view controller. The navigation controller shows the title, buttons, etc. of the current view controller it is displaying. – rmaddy Jul 07 '14 at 04:09
  • 1
    @GabeJacobs you have to write this code in UIViewController, not in UINavigationController. – Yogesh Suthar Jul 07 '14 at 04:09
  • @rmaddy So I'm a little confused. I put a UIViewController in the tab bar instead? And then where do I place the uinavigationcontroller? – evenodd Jul 07 '14 at 04:15
  • I figured it out, thanks to both of you! – evenodd Jul 07 '14 at 04:24
  • @GabeJacobs That's not what I said. The root of the tab is your navigation controller. You have set a view controller as the root of the navigation controller. That's all fine. What you need to do is move all (most) of the `viewDidLoad` code you posted from the navigation controller class to the view controller class. It is the view controller that defines its title and navbar buttons. The navigation controller automatically shows those details for whatever view controller it is currently displaying. – rmaddy Jul 07 '14 at 04:24
  • If issue is resolved, that can be posted as an answer. Accept that answer and close the ticket. – rishi Jul 07 '14 at 04:28

0 Answers0