navigationController标题

Jar*_*mes 18 controller objective-c uinavigationcontroller ios

我正在使用导航控制器开发应用程序.我知道如何在最初加载视图时设置标题.我推了一个新的视图控制器并设置它的标题.现在的问题是,当我按下后退按钮时,原始视图控制器的标题不再存在.我试着做...

- (void)viewWillAppear:(BOOL)animated {
    self.navigationController.title = @"Some Title";
}
Run Code Online (Sandbox Code Playgroud)

虽然这没有设定标题.有谁知道我能做什么?

Chr*_*r A 39

UINavigationController从当前的UIViewController获取标题的值.

要为视图控制器设置标题,只需执行以下操作:

- (void)viewDidLoad {

   [super viewDidLoad];
   self.title = @"Some Title";
}
Run Code Online (Sandbox Code Playgroud)

对于每个View Controller,包括根控制器.


Fed*_*deH 10

尝试更改导航项的标题.

[self.navigationItem setTitle:@"Some Title"];
Run Code Online (Sandbox Code Playgroud)


Wil*_*son 7

Swift 3中:

navigationItem.title = "Custom title"
Run Code Online (Sandbox Code Playgroud)

或者如果您想自定义标题的详细信息:

let titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
titleLabel.textColor = UIColor.red
titleLabel.text = "Hello"
titleLabel.textAlignment = .center
titleLabel.backgroundColor = UIColor.green
titleLabel.font = UIFont(name: "Baskerville-Bold", size: 20)
navigationItem.titleView = titleLabel
Run Code Online (Sandbox Code Playgroud)