Swift 3:我无法隐藏“后退”按钮

jor*_*rjj 1 back-button uitabbarcontroller uinavigationitem swift

我正在使用Tab Bar Controller,上面有2个视图控制器。在此之前,我还有另一个viewController来访问选项卡栏。当我看到标签栏时,后退按钮总是消失。我想隐藏后退按钮,并使用另一个按钮作为左按钮,但是我无法隐藏后退按钮。

这是viewController中Tab栏之前的代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "mainvc"{
        if pinLabel.text == pinPassword && pinLabel.text != ""{
            let tabBarController = segue.destination as! UITabBarController
            let destinationViewController = tabBarController.viewControllers?[0] as! ViewController

            destinationViewController.login.email = login.email
            destinationViewController.login.firstname = login.firstname
            destinationViewController.login.lastname = login.lastname
            destinationViewController.login.imageURL = login.imageURL
            destinationViewController.login.id = login.id                
        }else{

        }

    }
}
Run Code Online (Sandbox Code Playgroud)

这是我要隐藏后退按钮并将另一个按钮放入视图控制器之一的代码,这是我在访问选项卡栏控制器时看到的视图控制器:

let leftOpenSideBarMenu: UIBarButtonItem = UIBarButtonItem(image: myimage, style: .plain, target: self, action: #selector(ViewController.openSideBarMenu))
self.navigationItem.setHidesBackButton(true, animated: false)
self.navigationItem.setLeftBarButtonItems([leftOpenSideBarMenu], animated: true)
Run Code Online (Sandbox Code Playgroud)

Bha*_*iya 5

尝试

self.tabBarController.navigationItem.setHidesBackButton(true, animated: false)
self.tabBarController.navigationItem.setLeftBarButtonItems([leftOpenSideBarMenu], animated: true)
Run Code Online (Sandbox Code Playgroud)

代替

self.navigationItem.setHidesBackButton(true, animated: false)
self.navigationItem.setLeftBarButtonItems([leftOpenSideBarMenu], animated: true)
Run Code Online (Sandbox Code Playgroud)