ios - UINavigation 标题不显示?

标签 ios xcode uinavigationbar

这在我看来确实加载了。完全没有显示标题?我有一个 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/

相关文章:

Xcode:在项目中查找不仅仅是整个单词?

iphone - 将自定义 UINavigationBar 与 initAsRootViewController 一起使用 :

ios - 下推所有 View 并添加自定义 View

ios - MKMapView 调用 didSelectAnnotationView

ios - 使用 Swift 提取文本

ios - 更改图片背景图片

ios - 如何在应用程序进入后台时发送本地通知

ios - iOS 14 的 RSS 小部件显示为空

ios - Xcode 7 Git 安装失败 : unable to auto-detect email address

ios - 寻找 View 的中心