导航控制器标题

发布于 2024-12-08 03:04:56 字数 258 浏览 0 评论 0原文

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

绳情 2024-12-15 03:04:56

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

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

- (void)viewDidLoad {

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

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

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.

眼眸印温柔 2024-12-15 03:04:56

尝试更改导航项的标题。

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

Try changing the navigation item's title.

[self.navigationItem setTitle:@"Some Title"];
我是男神闪亮亮 2024-12-15 03:04:56

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

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
感性 2024-12-15 03:04:56

尝试这样设置你的标题。

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

Try setting your title this way.

self.navigationItem.title = @"My Title";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文