Search code examples
swiftuinavigationcontrolleruinavigationbaruisearchbaruisearchcontroller

Swift: Back button should be pressed twice while SearchBar is active


I have a UITableViewController embedded in a navigation bar and standard Search bar implementation. I don't hide the navigation bar while the search bar is active. The problem is that while the search bar is active, every button in the navigation bar, like a "Back" button, should be pressed twice— the first time to make the search bar inactive. How can I avoid that? Thank you.


Solution

  • add this codes on viewDidLoad

        self.definesPresentationContext = true
    

    and add this if your navigationBar is Opaque

        self.extendedLayoutIncludesOpaqueBars = true