UINavigationController 中未显示简单标题

人气:1,025 发布:2022-10-16 标签: ios uinavigationcontroller uinavigationitem uitabbaritem

问题描述

我查看了所有类似/相关的问题,但没有一个 a) 完全是我的问题,或者 2) 解决方案不起作用.

I have looked at all of the similar/related questions, but none either a) are exactly my problem or 2) the solutions just don't work.

在我的 appDelegate.m 中有 didFinishLaunchingWithOptions

In my appDelegate.m I have in didFinishLaunchingWithOptions

JCGRootNavigationController *rnc = [[JCGRootNavigationController alloc] init];
self.window.rootViewController = rnc;`

JCGRootNavigationController 是 UINavigationController 的子类

JCGRootNavigationController is a subclass of UINavigationController

@interface JCGRootNavigationController : UINavigationController`

在 JCGRootNavigationController.m 中:

In JCGRootNavigationController.m:

@implementation JCGRootNavigationController

-(instancetype) init {
    self = [super init];
    self.view.backgroundColor = [UIColor lightGrayColor];
    self.navigationItem.title = @"MY TITLE";    
    return self;
}

而且标题不会显示.我看到导航栏,但没有标题.看起来多年来很多人都遇到过同样的问题.也许一个简单的答案将有助于消除所有的困惑.这真是令人难以置信的令人沮丧.

And the title just won't display. I see the Navigation Bar, but no title. Looks like lots of people over the years have had this same problem. Maybe a simple answer will help clear up all of the confusing. This is so incredibly frustrating.

推荐答案

UINavigationController 自动显示它正在显示的 UIViewController 子类的标题.它通过查看 UIViewController 或 UIViewController 子类的 navigationItem.title 属性来实现.基本上 UINavigationController 没有标题.

UINavigationController automatically shows the title of the UIViewController subclass it is displaying. It does so by looking at the navigationItem.title property of that UIViewController or UIViewController subclass. Basically UINavigationController doesn't have a title.

844