Search code examples
swift3back-buttonuinavigationitem

Swift Hides back button


I want to hide the back button and set a title.

I'm using the following code:

    override func viewDidLoad() {
    super.viewDidLoad()

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

But the title isn't shown and the back button is still there but if I touch it nothing happens. Can anybody help me please?


Solution

  • I found a solution on my own.

    If I'm setting the title and the hidesBackButton from my previous ViewController everything works fine.

        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    
        if let destinationVC = segue.destination as? ViewControllerFirstSettings {
    
            destinationVC.navigationItem.hidesBackButton = true
            destinationVC.navigationItem.title = "Einstellungen"
        }
    }