【问题标题】:Set navigation item title on a TableViewController child of UISideMenuNavigationController not working在 UISideMenuNavigationController 的 TableViewController 子项上设置导航项标题不起作用
【发布时间】:2017-08-16 18:23:13
【问题描述】:

我正在尝试以编程方式为我的 rootViewController 设置标题,但它不起作用。

func configurarMenuRightNavigationController() {

        SideMenuManager.menuFadeStatusBar = false

        let menuRightNavigationController = storyboard!.instantiateViewController(withIdentifier: "RightMenuNavigationController") as! UISideMenuNavigationController

        //let menuRightNavigationController = UISideMenuNavigationController(rootViewController: YourViewController)
        // UISideMenuNavigationController is a subclass of UINavigationController, so do any additional configuration
        // of it here like setting its viewControllers. If you're using storyboards, you'll want to do something like:

        SideMenuManager.menuRightNavigationController = menuRightNavigationController

        SideMenuManager.menuRightNavigationController?.viewControllers[0].navigationItem.title = "Teste"

        SideMenuManager.menuPresentMode = .viewSlideOut
    }

标题不变。

当我在常规 UINavigationController 上尝试另一个没有侧边菜单的项目时,它可以工作。

【问题讨论】:

  • 我怀疑问题在于您试图更改一个全新创建的导航控制器的标题,该控制器还没有任何视图控制器。如果您执行“if let topViewController = SideMenuManager.menuRightNavigationController?.viewControllers[0]”,然后在topViewController 不为零的情况下打印一些内容(或设置断点),它会命中吗?
  • 是的,我想过,但我无法实例化正确的控制器。我怎么能这样做?

标签: swift uinavigationitem


【解决方案1】:

当我创建一个自定义 UITableViewController 并将其设置为 Storyboard 上 Table View Controller 的视图控制器时,它起作用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2018-12-07
    相关资源
    最近更新 更多