iOS.Blog.SwiftUI_Search_Bar_in_Navigation_Bar icon indicating copy to clipboard operation
iOS.Blog.SwiftUI_Search_Bar_in_Navigation_Bar copied to clipboard

How to show searchbar on load

Open skunkworker opened this issue 3 years ago • 4 comments

Hi, thanks for making this clean example of adding a searchbar. I've been looking but unable to find a way to show the SearchBar by default without having to pull down on the view. Is there a simple way to change this? Thanks

skunkworker avatar Dec 19 '20 22:12 skunkworker

I'm interested too

aksonov avatar Dec 23 '20 16:12 aksonov

is there any update on a solution?

FUNKYJASPER2 avatar Mar 10 '21 05:03 FUNKYJASPER2

Please take a look at these other branches below as well, as in some cases there is a search bar visible when the view opens.

Prototype/UI/UIKit_Navigation_Stack Prototype/UI/UIKit_Navigation Prototype/UI/SwiftUI_Navigation

Geri-Borbas avatar Mar 12 '21 12:03 Geri-Borbas

@skunkworker @aksonov @FUNKYJASPER2 Hi, guys👋. If the question is still relevant, for (iOS 13.0, *) and SwiftUI add the following:

ViewControllerResolver { viewController in 
        viewController.navigationItem.searchController = self.searchBar.searchController
        viewController.navigationController?.navigationBar.sizeToFit() // This line rocks
 }

Original StackOverflow answer: https://stackoverflow.com/a/67721006

Y-Rov avatar Mar 09 '23 15:03 Y-Rov