Is there any way to recieve a notification when a UISearchBar is finished (e.g Cancel button clicked or otherwise lost focus.
We don't have access to the UITextField inside, or I could attach an obser开发者_如何学Gover to it.
I can be notified when the keyboardWillHide, but I've got another text field, so it could be either one. And it becomes inactive before the keyboard hides, so no love.
I have access to the UISearchBarDelegate and UISearchDisplayController(Delegate).
Can anyone tell me where to look? Is there a master list of all notifications to choose from?
These methods should do it for you:
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar; // called when text ends editing
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar; // called when keyboard search button pressed
- (void)searchBarBookmarkButtonClicked:(UISearchBar *)searchBar; // called when bookmark button pressed
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar; // called when cancel button pressed
These are all UISearchBarDelegate delegate methods. By rule, delegate methods are more closely bound than adding observers for notifications. This was mentioned in one of Stanford University's iPhone videos. Though i myself use notifications generously and have found no problem with them.
In general, if there is not a Notifications section in the Apple docs for a class then there are no notifications that a publicly available for said class.
I would go with Chintan's suggestion of using the delegate.
精彩评论