0

I have a UISearchBar which I am putting in UISearchDisplayController. Now, whenever I tap on the 'Search' button on the keyboard, it dismisses the keyboard. I am implementing the below method to stop searching whenever 'Search' button is tapped in which case I do not want to loose my keyboard also. Is there any way to instruct UISearchDisplayController to not dismiss the keyboard on tap on 'Search' button?

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar1 {
     if ([searchBar.text length] < 3){
          return;
     }
     else {
          // Do searching here or other stuffs
     }
}
4

1 に答える 1

4

//このメソッドはNOを返し、ファーストレスポンダーを辞任しません

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar; 

したがって、コードでは、検索ボタンのタップだけでキーボードが閉じないようにするために、このようなものにする必要がありますが、キャンセルなどでは閉じます。

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar1 {
     isSearchTap = YES;
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
   if(isSearchTap) {
    return NO;
   }
   return YES;
}
于 2012-06-15T00:37:16.520 に答える