如何正确设置UIViewController的navigationController标题?

Rya*_*van 5 iphone uitabbarcontroller uinavigationcontroller ios

我正在尝试以下代码:

- (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];
}
Run Code Online (Sandbox Code Playgroud)

我认为这是你正确设置推动控制器的标题的方式.我尝试了thing.title但是设置了TabBarItem的标题.

jam*_*pag 19

thing.navigationItem.title = sub.title;
Run Code Online (Sandbox Code Playgroud)

或者在viewDidLoad方法中的StoriesViewController.m文件中:

self.navigationItem.title = sub.title
Run Code Online (Sandbox Code Playgroud)

  • 嗨,我试过self.navigationController.title = @"注册"; 有什么不同?这是行不通的 (2认同)