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

Sign up to request clarification or add additional context in comments.

4 Comments

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.
on beginning textFieldShouldClear method is called
Thank you! I missed that method you mentioned last. That did the trick in the pair of ...DidEndEditing!
@wm.p1us - nothing problem, small mistake thats all

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.