I am debugging my code where the delegate method UISearchBar searchBarTextDidBeginEditing: is called exactly twice every time I click on the search bar (which is in the navigation bar).
It is odd that only this delegate method is called twice. Others are called only once during the whole process, which is the correct behavior.
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { // called only once return YES; } - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { // called twice every time [searchBar setShowsCancelButton:YES animated:YES]; } - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar { // called only once [searchBar setShowsCancelButton:NO animated:YES]; return YES; } - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { // called only once }
Any idea what could be wrong?
UISeachrBar is configured in Storyboard with correctly connected outputs, although it is not added to any view, and in a specific view controller, viewDidLoad is the following line, which adds a search bar to the navigation bar:
self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
I use Xcode 5.0.1 and run the code in iOS 7.0.3 Simulator.
source share