0

I already read multiple posts regarding this, but couldn't get it working.

Posts I already read:

  1. Custom rightBarButtonItem disappearing
  2. RightBarButtonItem disappears when view appears again

I have a ViewController-A embedded in a UINavigationController. The navigation bar of the controller contains a rightBarButtonItem. Code for adding rightBarButtonItem:

let searchButton = UIBarButtonItem(image: UIImage(named: "HomeSearch"), style: .plain, target: self, action: #selector(navigateToSearchScreen))
self.navigationItem.rightBarButtonItem = searchButton

When another ViewController-B is pushed in the navigation stack and popped back, the rightBarButtonItem disappears from the navigation bar.

PGDev
  • 23,751
  • 6
  • 34
  • 88

1 Answers1

0

I think in nextViewcontroller you hide the navigation right bar so When you pop then nav button will not display So You have to add right bar button in viewWillAppear:

override func viewWillAppear(_ animated: Bool) {
        let searchButton = UIBarButtonItem(image: UIImage(named: "HomeSearch"), style: .plain, target: self, action: #selector(navigateToSearchScreen))
        self.navigationItem.rightBarButtonItem = searchButton
    }
Jogendar Choudhary
  • 3,476
  • 1
  • 12
  • 26