Search bar delegate - difference between searchBarShouldBeginEditing / searchBarTextDidBeginEditing?

1.8k views Asked by At

What's the difference between them? In my experimentation, they seem to get called during the same action - once the user taps the search bar to bring up the keyboard. This is despite the user not having editing the actual text yet. Which seems to call searchBar:textDidChange. But that gets called for each change, not just once at the beginning. Which means I have to write more code to duplicate how the Search Bar behaves in Google Maps.

OK, so that turned more into venting - but maybe I'm missing something. Are there cases in which searchBarShouldBeginEditing is called but not searchBarTextDidBeginEditing - or vice-versa?

1

There are 1 answers

0
Ben Gottlieb On BEST ANSWER

Any message with "should" in the name is expected to return a boolean. If that's false, then, in this case, editing is not begun, and the search bar does not becomeFirstResponder (ie, the user taps on it, but no keyboard appears for editing).