iPhone UISearchBar takes two clicks to be selected
I have a UISearchBar in my app, and I'm running the following code with it:
- (void)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
    [searchBar setShowsCancelButton:YES animated:YES];
}
So when the user clicks the search bar, a cancel button pops up next to it.
This, unfortunately, makes it 开发者_运维问答so the text box isn't selected, and the keyboard doesn't pop up. You have to click the search bar a second time to get those things to happen.
How would I fix this?
Thanks.
The method should be like this:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
    [searchBar setShowsCancelButton:YES animated:YES];
    return YES;
}
The key element is returning YES in this method to indicate that it should in fact begin editing.
Documentation here: http://developer.apple.com/library/ios/documentation/uikit/reference/UISearchBarDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UISearchBarDelegate/searchBarShouldBeginEditing:
could you change your code as below
 [searchBar setShowsCancelButton:NO animated:YES];
I think your were passing YES in the above method.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论