简体   繁体   中英

UINavigation title not showing?

This is in my view did load. There is no title showing at all? I have a UITabBar with a UITableView and UInavigationBar inside the UITabBar.

//Creates navigation bar.
UINavigationBar *myNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
myNavBar.barStyle = UIBarStyleBlack;
myNavBar.topItem.title = @"My Title";

[self.view addSubview:myNavBar];
myNavBar.topItem.title = @"My Title";

doesn't work because topItem is nil since there is no item. You need to add UINavigationItem s.

self.title = @"Some Title";

doesn't work because UINavigationController picks up UIViewController 's title and there is no UINavigationController here.

self.navigationItem.title=@"My Title"";

doesn't work because navigationItem is nil.

Solution:

Add an item (and set the title in the UINavigationItem ) using either -[UINavigationBar pushNavigationItem:animated:] or -[UINavigationBar setItems:]

Use this

self.navigationItem.title=@"My Title"";

It may help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM