Hide back button in navigation bar with hidesBackB

2019-03-09 01:16发布

I want to hide the back button when transitioning from one view to another. I read the questions regarding this problem and every answer was "use hidesBackButton". The problem with this is:

  • when I put it in viewDidLoad/viewWillAppear the back button arrow hides but the string "Back" doesn't.

  • when I put it in viewDidAppear the back button disappears but it visible to the user

How can I fix this?

Edit:

Here is how you can replicate this problem(or bug?)
Make a new Tabbed application with Swift in Xcode. In the FirstViewController.swift use performSegueWithIdentifier to navigate to the second view controller. In the SecondViewController.swift hide the navigation bar back button using hidesBackButton and you will see what the problem is.

8条回答
一夜七次
2楼-- · 2019-03-09 02:10

this worked for me

navigationController?.navigationBar.topItem?.hidesBackButton = true
查看更多
成全新的幸福
3楼-- · 2019-03-09 02:12

To hide the back button with the latest Swift:

self.navigationItem.setHidesBackButton(true, animated: false)
查看更多
登录 后发表回答