这在我看来确实加载了。完全没有显示标题?我有一个 UITabBar,UITabBar 内有一个 UITableView 和 UInavigationBar。
//Creates navigation bar.
UINavigationBar *myNavBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
myNavBar.barStyle = UIBarStyleBlack;
myNavBar.topItem.title = @"My Title";
[self.view addSubview:myNavBar];
最佳答案
myNavBar.topItem.title = @"My Title";
不起作用,因为 topItem
为 nil,因为没有项目。您需要添加 UINavigationItem
。
self.title = @"Some Title";
不起作用,因为 UINavigationController
获取了 UIViewController
的标题,而这里没有 UINavigationController
。
self.navigationItem.title=@"My Title"";
不起作用,因为 navigationItem
为 nil。
解决方案:
使用 -[UINavigationBar pushNavigationItem:animated:]
或 -[UINavigationBar setItems:]< 添加项目(并在
UINavigationItem
中设置标题)/
关于ios - UINavigation 标题不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16321889/