开发者

Cocoa Touch: Setting UINavigationController's title doesn't work

I've used [[self navigationController] setTitle:@"Test Title"] to no avail.开发者_Go百科 This is the same way I do it in the rest of my app. What could cause this?


Try setting the title of the navigation item.

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

Or like this if you prefer

[[self navigationItem] setTitle:@"Test Title"];


You are using the title property incorrectly, the navigationController has a title property because it inherets from UIViewController, the title property is used by NavigationControllers to display a title, so if you wanted the title you gave your NavigationController to show you would need to present it in another NavigationCOntroller...But what you need to do, is set the viewControllers that you are displaying titles instead of the NavigationController, now whenever u display that VC youll see the title in the navigation bar... In short...the viewcontrollers title property is used by its navigationController to display the title on the navigation bar when that viewcontroller is on the top of the navigation stack...


CustomViewController *viewController = [[CustomViewController alloc] init];
[viewController setTitle:@"CustomViewController!";
[custonNavigationController pushViewController:viewController animated:YES];

This is a simplification of what Daniel had said. This method properly follows stack protocol.


SecondViewController *s1=[[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil];
[s1 setTitle:@"Second Page"];
[self pushViewController:s1 animated:YES];

Worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜