navigationController标题

时间:2011-10-04 06:11:06

标签: objective-c ios uinavigationcontroller controller

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

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

但这并没有设定标题。有谁知道我能做什么?

4 个答案:

答案 0 :(得分:39)

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

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

- (void)viewDidLoad {

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

对于每个视图控制器,包括根控制器。

答案 1 :(得分:10)

尝试更改导航项的标题。

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

答案 2 :(得分:7)

Swift 3

navigationItem.title = "Custom 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

答案 3 :(得分:0)

尝试以这种方式设置标题。

self.navigationItem.title = @"My Title";
相关问题