我有一个用于通用项目列表的 Controller / View ,可以扩展它以显示自定义列表。列表和导航工作正常。但我无法更改 UINavigationController 的标题。 在通用 Controller 中:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view addSubview: navigationController.view];
}
- (void)setNavigationTitle: (NSString *)title
{
NSLog(@"set title: %@", title); // this works
self.navigationController.title = title; // Nothing works here
}
然后,扩展类会......
- (void)viewDidLoad
{
[super viewDidLoad];
[self setNavigationTitle: @"Custom list"];
}
导航栏的标题仍然是“Item”:(
最佳答案
在您的 UIViewController
中有一个 title
属性,NavigationController
将显示该属性。因此,当将新的 UIViewController
推送到导航堆栈时,将该 UIViewController
的标题设置为适当的标题。
在你的情况下它看起来像:
[self setTitle:@"WhateverTitle"];
关于ios - UINavigationController 如何设置标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3959003/