在 UITabBar 中强制执行静态标题

Enforce static title in UITabBar

我正在使用 UITabBar,其第一个选项卡与 UINavigationController 相关。 UINavigationController 的根视图控制器的 viewWillAppear: 将该视图控制器(以及导航控制器)的标题设置为当前月份符号。这也隐含地更改了标签栏中显示的标题。

如何实现选项卡栏显示静态标题(例如 "Calendar")而其相关导航控制器仍显示动态标题(例如 "December")的替代情况?

以下解决方案现在适用于我。 MonthViewControllerUINavigationController 的根视图控制器。

class MonthViewController: UIViewController {

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)

        // calculate monthSymbol ...

        self.title = monthSymbol

        let tabBarController = self.navigationController!.parentViewController as! UITabBarController
        tabBarController.tabBar.items![0].title = "Calendar"
    }
}