0

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!

1 Answer 1

1

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

5
  • Thank you. But when I just tapped on search field it still can be covered by navigation controller. Your method shows that I can change property of navigation controller only after search filed gets "" not from the beginning.
    – wm.p1us
    Oct 6, 2016 at 11:08
  • on beginning textFieldShouldClear method is called Oct 6, 2016 at 11:09
  • Thank you! I missed that method you mentioned last. That did the trick in the pair of ...DidEndEditing!
    – wm.p1us
    Oct 6, 2016 at 11:22
  • 1
    @wm.p1us - nothing problem, small mistake thats all Oct 6, 2016 at 11:22
  • Thank you. It is also helped me Oct 6, 2016 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.