Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Title not showing up in UINavigationController

I have looked at all of the similar/related questions, but none either a) are exactly my problem or 2) the solutions just don't work.

In my appDelegate.m I have in didFinishLaunchingWithOptions

JCGRootNavigationController *rnc = [[JCGRootNavigationController alloc] init];
self.window.rootViewController = rnc;`

JCGRootNavigationController is a subclass of UINavigationController

@interface JCGRootNavigationController : UINavigationController`

In JCGRootNavigationController.m:

@implementation JCGRootNavigationController

-(instancetype) init {
    self = [super init];
    self.view.backgroundColor = [UIColor lightGrayColor];
    self.navigationItem.title = @"MY TITLE";    
    return self;
}

And the title just won't display. I see the Navigation Bar, but no title. Looks like lots of people over the years have had this same problem. Maybe a simple answer will help clear up all of the confusing. This is so incredibly frustrating.

like image 916
Chris C Avatar asked Jul 03 '14 22:07

Chris C


2 Answers

When working with a Storyboard, setting the title of the UIViewController or UITableViewController does not seem to add that title to the Navigation Controller, as other answers suggest.

Instead, find the UINavigationItem that is likely alongside your View Controller object in the Storyboard hierarchy. Set this Navigation Item's title to apply that title to the Navigation Controller.

Navigation Item on Storyboard[1]

like image 107
pkamb Avatar answered Oct 26 '22 12:10

pkamb


UINavigationController automatically shows the title of the UIViewController subclass it is displaying. It does so by looking at the navigationItem.title property of that UIViewController or UIViewController subclass. Basically UINavigationController doesn't have a title.

like image 38
JackyJohnson Avatar answered Oct 26 '22 11:10

JackyJohnson