Swift - How to hide back button in navigation item?

后端 未结 9 899
走了就别回头了
走了就别回头了 2020-11-30 23:06

Right now I have two view controllers. My problem is I don\'t know how to hide the back button after transitioning to the second view controller. Most references that I foun

相关标签:
9条回答
  • 2020-11-30 23:41

    Swift

    // remove left buttons (in case you added some)
     self.navigationItem.leftBarButtonItems = []
    // hide the default back buttons
     self.navigationItem.hidesBackButton = true
    
    0 讨论(0)
  • 2020-11-30 23:43

    Put it in the viewDidLoad method

    navigationItem.hidesBackButton = true 
    
    0 讨论(0)
  • 2020-11-30 23:45

    In case you're using a UITabBarController:

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        self.tabBarController?.navigationItem.hidesBackButton = true
    }
    
    0 讨论(0)
  • 2020-11-30 23:46

    According to the documentation for UINavigationItem :

    self.navigationItem.setHidesBackButton(true, animated: true)
    
    0 讨论(0)
  • 2020-11-30 23:49

    This is also found in the UINavigationController class documentation:

    navigationItem.hidesBackButton = true
    
    0 讨论(0)
  • 2020-11-30 23:53

    That worked for me in Swift 5 like a charm, just add it to your viewDidLoad()

    self.navigationItem.setHidesBackButton(true, animated: true)
    
    0 讨论(0)
提交回复
热议问题