UINavigationController如何设置标题 [英] UINavigationController how to set title

查看:427
本文介绍了UINavigationController如何设置标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用的项目列表的Controller / View,可以扩展用于显示自定义列表..列表和导航工作正常..但我无法更改UINavigationController的标题。
在通用控制器中:

I have a Controller/View for a generic list of items, that can be extended for displaying a custom list.. Listing and navigation works fine.. but I can't change the title of UINavigationController. In the generic Controller:

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view addSubview: navigationController.view];
}
- (void)setNavigationTitle: (NSString *)title
{
    NSLog(@"set title: %@", title); // this works
    self.navigationController.title = title; // Nothing works here
}

然后,扩展类会这样做..

Then, the extended class does..

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setNavigationTitle: @"Custom list"];
}

navigationBar仍有Item作为标题:(

The navigationBar still have "Item" as title :(

推荐答案

UIViewController 中有一个标题属性,它是由 NavigationController 显示的属性。所以当推送一个新的 UIViewController 时导航堆栈将 UIViewController 的标题设置为适当的值。

In your UIViewController there is a title property and it is that property that will be displayed by the NavigationController. So when pushing a new UIViewController onto the navigation stack set the title of that UIViewController to whatever is appropriate.

在你的情况下它看起来会像be:

In your case it looks like it would be:

[self setTitle:@"WhateverTitle"];

这篇关于UINavigationController如何设置标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆