navigationController title

孤街浪徒 提交于 2020-08-03 12:21:11

问题


I am working on an app with a navigation controller. I know how to set the title when the view loads initially. I push a new view controller and set it's title. Now the problem is when I press the back button, the title for the original view controller is not there anymore. I tried to do...

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

This did not set the title though. Does anyone know what I can do?


回答1:


The UINavigationController gets the value for the title from the current UIViewController.

To set a the title for a view Controller, simply do the following:

- (void)viewDidLoad {

   [super viewDidLoad];
   self.title = @"Some Title";
}

For each of your View Controllers, including the root one.




回答2:


Try changing the navigation item's title.

[self.navigationItem setTitle:@"Some Title"];



回答3:


in Swift 3:

navigationItem.title = "Custom title"

or if you want to customize the details of the title:

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



回答4:


Try setting your title this way.

self.navigationItem.title = @"My Title";


来源:https://stackoverflow.com/questions/7643901/navigationcontroller-title

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!