UISearchController is hidden initially until I scroll down.

I have been implementing a UISearchController, I add it to the navigationItem of the view. When the view loads, it is hidden until I scroll down to show it. I want it to be shown initially. I have changed the navigationItem.hidesSearchBarWhenScrolling to false, it solved the initial problem but I also want it to be hidden when the user is scrolling through the collectionView of the view. I am currently using Swift 6 and iOS 18+. I will add the current configuration function.

private func configureSearchController() {
        let searchController = UISearchController()
        searchController.searchResultsUpdater = self
        searchController.searchBar.delegate = self
        searchController.searchBar.placeholder = "Search for a username"
        searchController.obscuresBackgroundDuringPresentation = false
        navigationItem.searchController = searchController
        navigationItem.hidesSearchBarWhenScrolling = false
    }
    
Answered by Archonie in 817259022

Update: I have figured it out. I used the scrollViewWillBeginDragging function to reassign the navigationItem.hidesSearchBarWhenScrolling to true. It solved my problem.

Accepted Answer

Update: I have figured it out. I used the scrollViewWillBeginDragging function to reassign the navigationItem.hidesSearchBarWhenScrolling to true. It solved my problem.

UISearchController is hidden initially until I scroll down.
 
 
Q