Stopping UISearchDisplayController to dismiss the searchbar keyboard

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
     }
}

// This method return NO to not resign first responder

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

So on your code it should be something like this to avoid the keyboard not to dismiss on search button tap only, but will dismiss on cancel, etc.

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

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
   if(isSearchTap) {
    return NO;
   }
   return YES;
}
链接地址: http://www.djcxy.com/p/44240.html

上一篇: UISearchBar取消按钮没有响应

下一篇: 停止UISearchDisplayController关闭搜索栏键盘