iphoneuisearchbar

UISearchBar cancel button not responding


I have implemented searchbar which shows cancel button once user has focus in searchbar. For this I have written searchBar.showsCancelButton = YES; in my searchBarTextDidBeginEditing method. In searchBarSearchButtonClicked, I resign the keyboard so that user can view full tableview.

Problem: At this point the searchbar cancel button is not responding. It only responds once searchbar gets focus again. Is this the default property of search bars cancel button or am I missing something in my code. I want to use cancel button without giving the focus in searchbar again.


Solution

  • This is search bar cancel button's default behaviour. If you want other functionality, you can just uncheck cancelbutton property for search bar and can use UIButton as cancel button.