Reputation: 2069
I have navigation controller which has .hidesBarOnSwipe = true. As well when I perform search my navigation controller goes up and hides (as it should by default).
But if I try search something and then press (x) to clean what I've already written my navigation bar overlaps search bar but the second is still active and I can write something and it performs search.
So the question is how I can find method that invoked when I tap (x) button on search bar.
And how can I make my navigation bar be fixed and hidden while my search bar is still active because if it is still active I can swipe down I got my navigation bar overlapping search bar again?
Thank you!
Upvotes: 0
Views: 312
Reputation: 82756
you can get this function of X pressed
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
if searchText == "" {
print("SearchBar text cleared!")
// do something whatever you need
}
}
or use
func textFieldShouldClear(textField: UITextField) -> Bool {
// do something here
return true
}
Swift3
func textFieldShouldClear(_ textField: UITextField) -> Bool {
// do something here
return true
}
or use this
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
if (searchBar.text == "") {
//Clear stuff here
}
}
for more information you can get the samples from here
Upvotes: 1