1
votes

I have an application where I need the navigation bar on only the listing screen and not the detailed screen (in most cases). I can easily achieve this by hiding the navbar in the detail screen using

self.navigationController?.setNavigationBarHidden(true, animated: false) //Added in viewWillAppear

Optionally, the listing screen also allows the user to search on tapping a button.

When the user taps on the search button, I add a searchController to the navigation bar

self.navigationItem.searchController = mySearchController

At this point if I take the user to the detailed view, the navigation bar does not hide on the detailed view. I tried adding the code to hide the navbar in viewDidAppear: and it works but shows a strange transition from navbar to no-navbar.

How can I get the navigation bar to hide in the detailed view when the searchcontroller is set in the previous screen? Thanks

1

1 Answers

0
votes

As from what I understand from your question is you want to hide navigation bar on detail view and show it again when you are in master view (let's say), if that is the case I would do something like this in the detail view

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.setNavigationBarHidden(true, animated: true)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    self.navigationController?.setNavigationBarHidden(false, animated: true)
}

Edit
Please be aware that with this implementation you will lose swipe back functionality