Swift 隐藏后退按钮

Swift Hides back button

我想隐藏后退按钮并设置标题。

我正在使用以下代码:

    override func viewDidLoad() {
    super.viewDidLoad()

    navigationItem.title = "Einstellungen"
    navigationItem.hidesBackButton = true }

但标题没有显示,后退按钮仍然存在,但如果我触摸它,则没有任何反应。有人可以帮我吗?

此代码可能有帮助:

 // MARK: - CUSTOM METHODS
        func createNavBar() {

            let leftNavigationButton =  UIButton()
            leftNavigationButton.setImage(UIImage(named: "ic_back.png"), forState: .Normal)
            leftNavigationButton.frame = CGRectMake(10, 10, 20, 15)
            leftNavigationButton.addTarget(self, action: "onBackButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
            let customBarItem = UIBarButtonItem(customView: leftNavigationButton)
            self.navigationItem.leftBarButtonItem = customBarItem;

            //set TitleAppIcon
            let GR = UITapGestureRecognizer(target: self, action: Selector("headerLogoTapAction:"))
            let imageView = UIImageView(frame: CGRect(x: 90, y: 0, width: ((UIScreen.mainScreen().bounds.width)/3), height: 40))
            imageView.addGestureRecognizer(GR)
            imageView.userInteractionEnabled = true
            navigationItem.titleView = imageView
        }

我自己找到了解决方案。

如果我设置标题和我以前 ViewController 的 hidesBackButton 一切正常。

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if let destinationVC = segue.destination as? ViewControllerFirstSettings {

        destinationVC.navigationItem.hidesBackButton = true
        destinationVC.navigationItem.title = "Einstellungen"
    }
}