代码之家  ›  专栏  ›  技术社区  ›  grilix

UINavigationController如何设置标题

  •  19
  • grilix  · 技术社区  · 14 年前

    我有一个通用项目列表的控制器/视图,可以扩展以显示自定义列表。。列表和导航工作正常。。但我不能更改UINavigationController的名称。

    - (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
    }
    

    然后,扩展类会。。

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

    5 回复  |  直到 8 年前
        1
  •  60
  •   willcodejavaforfood    14 年前

    在你的 UIViewController 有一个 title 属性,将由 NavigationController uiview控制器 在导航堆栈上设置 去做任何合适的事。

    在你的情况下,看起来会是:

    [self setTitle:@"WhateverTitle"];
    
        2
  •  10
  •   fiedl    8 年前

    对于那些寻求快速解决方案的人:

    class CustomViewController: SuperViewController {
      override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "My Custom Title"
      }
    }
    

    这个 title UIViewController 而不是在 UINavigationController 嵌入视图控制器。

    UIViewController Class Reference: title Property

        3
  •  5
  •   Gyani    14 年前

    使用

    self.title = @"yourTitle";
    
        4
  •  4
  •   SwiftArchitect    8 年前

    title = "whateverTitle" . 是一个 UIViewController 实例属性;随时调用。

    documentation :

    宣言
    var title: String? { get set }


    将标题设置为描述视图的可读字符串。如果视图控制器具有有效的导航项或选项卡栏项,则为此属性指定值将更新这些对象的标题文本。

        5
  •  0
  •   infiniteLoop    12 年前

    我知道这是老生常谈,但我想和你分享一下 在UIVIewControler派生类的“init”方法中设置“self.title”,