使用pushview控制器保持相同的导航栏颜色

时间:2018-01-16 19:32:40

标签: ios swift pushviewcontroller

我有一个带有导航控制器的应用程序,它连接到UIViewcontrollerA。在UIViewcontrollerA里面我有一个tableview,当用户点击一个单元格时,他们会被带到UIViewcontrollerB。 UIViewcontrollerB与故事板或任何导航控制器中的UIViewcontrolleA没有任何连接。我遇到的问题是,当点击转到UIViewcontrollerB时,导航栏会丢失其颜色值。有没有办法将值形式UIViewcontrollerA传递给UIViewcontrollerB而无需在UIViewcontrollerB中手动设置它? 谢谢你的帮助!

代码:

if let vc: UIViewcontrollerB = stbrd.instantiateViewController(withIdentifier: UIViewcontrollerB.UIViewcontrollerBIdentifier) as? UIViewcontrollerB {
  self.navigationController?.pushViewController(vc, animated: true)

}

2 个答案:

答案 0 :(得分:2)

确保在UIViewControllerB的身份检查器中,您尚未禁用导航栏。我之前遇到过这个问题,我不得不将顶栏设置为“推断”#39;。希望这会有所帮助。

答案 1 :(得分:1)

要更新所有视图控制器上的导航栏外观,请在appDelegate的didFinishLaunchingWithOptions方法中编写以下代码行:

   UINavigationBar.appearance().barTintColor = .black
    UINavigationBar.appearance().tintColor = .white
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
    UINavigationBar.appearance().isTranslucent = false
相关问题