UISearchController scope buttons disappear forever after dismissing search when embedded in a search tab

When a UISearchController is placed inside a search tab, the scope buttons disappear when dismissing the search bar once. They never return. When using in any regular view controller container, like even another default tab, everything works fine. Is there something I can do to prevent this?

Video: https://mastodon.social/@nicoreese/115017696077771370

FB19587916

 let homeTab = UITab(
            title: "Home",
            image: UIImage(systemName: "house"),
            identifier: "Home"
        ) { _ in
            UINavigationController(rootViewController: ViewController())
        }
        
        let searchTab = UISearchTab { _ in
            UINavigationController(rootViewController: SearchViewController())
        }

        let tabBarController = UITabBarController(tabs: [
            homeTab, searchTab
        ])
        tabBarController.mode = .tabSidebar
class SearchViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.backgroundColor = .systemBackground
        
        self.title = "Home"
        
        let searchController = UISearchController(searchResultsController: nil)
        
        searchController.searchBar.scopeButtonTitles = [
            "Scope 1", "Scope 2"
        ]
                
        searchController.searchBar.showsScopeBar = true
        
        self.navigationItem.searchController = searchController
    }
}

I filed two related UISearchBar scope button bug reports against beta 1. Still not fixed as of beta 5.

Though earlier today I found a work around that might work in your case too.

Set the search controller scopeBarActivation to .manual. Set the controller’s delegate. In the didPresentSearchController delegate method, call setShowScope(true, animated: true) on the search bar. In the willDismissSearchController delegate method, call setShowScope(false, animated: true) on the search bar. The latter one is key.

The result looks slightly clunky but at least the scope buttons appear more than once.

UISearchController scope buttons disappear forever after dismissing search when embedded in a search tab
 
 
Q