Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I correctly set a UIViewController's navigationController title?

I am trying 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 this is how you correctly set the title for pushing the controller. I tried thing.title however that was setting the TabBarItem's title instead.

like image 390
Ryan Sullivan Avatar asked Aug 01 '10 15:08

Ryan Sullivan


People also ask

How do I change the title of the navigation bar in Swift storyboard?

1: Select the "navigation item" from the document outline pane. 2: Open the attributes-inspector. 3: Select the title field and write the title here instead.

What is a navigation controller?

NavController manages app navigation within a NavHost . Apps will generally obtain a controller directly from a host, or by using one of the utility methods on the Navigation class rather than create a controller directly. Navigation flows and destinations are determined by the navigation graph owned by the controller.


2 Answers

thing.navigationItem.title = sub.title;

or in StoriesViewController.m file in viewDidLoad method:

self.navigationItem.title = sub.title
like image 61
jamapag Avatar answered Oct 12 '22 22:10

jamapag


It's possible you're pushing a UITabBarController instead of your regular view controller. In this case, the navigationItem will display the title of the current controller, the tab bar controller, even though you see another view. You would have to change the tab bar controller's title to change the text displayed above.

self.tabBarController.title = @"Your title";
like image 26
circuitlego Avatar answered Oct 12 '22 23:10

circuitlego