斯威夫特隐藏后退按钮

时间:2016-12-17 12:30:24

标签: swift3 back-button uinavigationitem

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

我正在使用以下代码:

    override func viewDidLoad() {
    super.viewDidLoad()

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

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

2 个答案:

答案 0 :(得分:2)

我自己找到了一个解决方案。

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

{{1}}

答案 1 :(得分:0)

此代码可能有所帮助:

 // 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
        }