2017-03-31 24 views
0

我发现setNavigationBarHiddensetViewControllers后不起作用?setNavigationBarHidden在setViewControllers后不工作

这是我的代码:

  • HomeNavController.swift

    class HomeNavController: UINavigationController { 
    
        weak var tabBar: HomeTabBar! 
    
        var tab: HomeTab = .match { 
         didSet { 
          switch self.tab { 
          case .match: 
           self.setViewControllers([MatchViewController()], animated: false) 
          case .moments: 
           self.setViewControllers([MomentsViewController()], animated: false) 
          case .myPosts: 
           self.setViewControllers([PostsViewController()], animated: false) 
          } 
         } 
        } 
    } 
    
  • MatchViewController.swift

    override func viewWillAppear(_ animated: Bool) { 
        super.viewWillAppear(animated) 
    
        self.navigationController?.setNavigationBarHidden(true, animated: false) 
    } 
    

它运作良好,当我第一次切换到MatchViewController实例,但在使用func setViewControllers更改HomeNavController实例的viewControllers后,它不起作用。

这是一个错误UINavigationController

+0

试戴ViewDidAppear? –

+0

你是否也将navigationController设置为隐藏在你的Moments&Posts ViewControllers中? –

+0

是的,我曾尝试ViewDidAppear,设置隐藏在我的时刻和帖子ViewControllers,但它没有工作。 – Leo

回答

0

也许尝试设置属性,这个工作在我的情况:

let navigationBarAppearance = UINavigationBar.appearance() 
    let transparentColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0); 
    // Sets the translucent background color 
    navigationBarAppearance.backgroundColor = transparentColor 
    navigationBarAppearance.titleTextAttributes = [NSForegroundColorAttributeName:transparentColor] 
    // Hides the border 
    navigationBarAppearance.shadowImage = UIImage() 
    navigationBarAppearance.setBackgroundImage(UIImage(), for: .default) 
+0

这看起来像个好主意,我会试试看它,谢谢。我仍然想知道如果我做错了什么,因为它不起作用... – Leo

+0

这是如何为你工作的? – velaru

+0

最后我发现这是我的错,我有一个自定义的导航栏...我认为你的答案在某些情况下是有用的。 – Leo

相关问题