How can I force the UISearchBar to automatically start a new search (like pressing the Search button)? Is there an easy way to achieve this?
You can force your searchBar,
Objective C:
[self searchBar:yourSearchBarName textDidChange: yourSearchingString];
Swift 3.0:
self.searchBar(self.yourSearchBarName, textDidChange: yourSearchingString)
This will trigger your searchBar.
Just have the search input field become the first responder:
[self.searchInputField becomeFirstResponder];
This worked - Swift 4
searchBar.text="Amber"
self.searchBar(self.searchBar, textDidChange: "Amber")
After making sure that the text you want is inside your search bar you can call self.searchBarSearchButtonClicked(searchBar)
(passing in your search bar) assuming you have already implemented this UISearchBarDelegate method searchBarSearchButtonClicked(_ searchBar: UISearchBar)
let searchBar: UISearchBar = /* The Searchbar */
searchBar.delegate?.searchBar?(searchBar, textDidChange: "")
searchBar.text = ""
Yes you only need to make an implicit call to the searchBarSearchButtonClicked:
on your UISearchbarDelegate
. Have a look to the official doc for more info about this delegate.