How to set UIViewController navigationController header correctly?

I am trying to execute the following code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 Thing *sub = [[subscriptions objectAtIndex:indexPath.row] retain];
 StoriesViewController *thing = [[StoriesViewController alloc] initWithThing:sub];
 thing.navigationController.title = sub.title;
 [self.navigationController pushViewController:thing animated:YES];
 [thing release];
 [sub release];

 [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

I thought that this is how you correctly configured the header for pressing the controller. I tried thing.title, however, the TabBarItem header was specified instead.

+5
source share
6 answers
thing.navigationItem.title = sub.title;

or in the StoriesViewController.m file in viewDidLoad:

self.navigationItem.title = sub.title
+14
source

The header must be set to (or after) viewDidLoad, so if you want to install from another class that creates the StoriesViewController.

  • Make another property and set this class.
  • StoriesViewController viewDidLoad .

, viewDidLoad.

, StoriesViewController sub ( initWithThing ?) , viewDidLoad Thing.

+1

, UITabBarController . navigationItem , , . , , .

self.tabBarController.title = @"Your title";
+1
[thing setTitle: sub.title];
0

The solution was thing.navigationItem.title = @"title";however, it turned out that subclassing a UINavigationControllerbroke it somehow, and my decision was to use a category, not a subclass

0
source

If yours UIViewControlleris part UITabController, you can do:

self.tabBarController.title = sub.title;
0
source

All Articles