iPhone SDK: UISearchBar: searchBarTextDidEndEditing not firing

浪尽此生 提交于 2019-12-18 06:57:01

问题


I'm implementing a search bar on my table, which should be pretty straight forward. I've got these:

- (void)searchBarTextDidBeginEditing:(UISearchBar *)theSearchBar { 
 NSLog(@"searchBarTextDidBeginEditing");
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {    
    NSLog(@"The search text is: %@", searchText);
}

- (void)searchBarTextDidEndEditing:(UISearchBar *)theSearchBar {
    NSLog(@"searchBarTextDidEndEditing");
    [theSearchBar resignFirstResponder];
}

And searchBarTextDidBeginEditing fires, and I get that message in my log, but when I tap outside the search bar, above the keyboard, I don't get the searchBarTextDidEndEditing event so I can't make the keyboard disappear – the message doesn't even appear in the log.

The textDidChange is working, so it's just searchBarTextDidBeginEditing that isn't.

Any ideas? Thanks!!


回答1:


Even i faced the same problem.

Please find with the solution below

Implement Below methods

1.searchBarTextDidEndEditing
2.searchBarSearchButtonClicked

and make sure you [UISearchchbar resignfirstresponder] in the second method mentioned above




回答2:


Once I implemented searchBarSearchButtonClicked that solved it for me.




回答3:


The method

  • (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar

is only called when [searchBar resignFirstResponder] is called.

The best place to call [searchBar resignFirstResponder] is in the method

  • (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

In swift:

  • (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar;
  • (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar;


来源:https://stackoverflow.com/questions/3359818/iphone-sdk-uisearchbar-searchbartextdidendediting-not-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!