斯威夫特3:我无法隐藏后退按钮

时间:2017-07-18 11:14:05

标签: swift uitabbarcontroller back-button uinavigationitem

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

这是Tab Bar前面的viewController中的代码:

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{

        }

    }
}

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

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)

1 个答案:

答案 0 :(得分:5)

尝试

self.tabBarController.navigationItem.setHidesBackButton(true, animated: false)
self.tabBarController.navigationItem.setLeftBarButtonItems([leftOpenSideBarMenu], animated: true)

而不是

self.navigationItem.setHidesBackButton(true, animated: false)
self.navigationItem.setLeftBarButtonItems([leftOpenSideBarMenu], animated: true)