My application has a search bar to search for records from a table view that is populated with sqlite DB. My problem is that when I open the view, the Cancel button is not turned on, and I canβt touch it, just like the image itself. It is, but no action is taken with this. when we click on the text of the search bar, the cancel button will be changed to "done", it will be turned on. so here is my code
this is my kind of search bar, see this cancel button. It is not included.

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { //[newSearchBar setShowsCancelButton:YES animated:YES]; newSearchBar.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters; NSLog(@"search begin edit") ; //searchString = searchBar.text; //NSLog(@"print did edit searchstring : %@", searchString) ; for(UIView *view in [searchBar subviews]) { //shareItemId =newSearchBar.text; if([view isKindOfClass:[NSClassFromString(@"UINavigationButton") class]]) { [(UIBarItem *)view setTitle:@"Done"]; } } - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { NSLog(@"searchBarTextDidEndEditing:"); [searchBar resignFirstResponder]; //[self dismissModalViewControllerAnimated:YES]; } - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { NSLog(@"searchBarSearchButtonClicked"); searchString = searchBar.text; NSLog(@"search %@", searchBar.text); [newSearchBar setShowsCancelButton:NO animated:YES]; [searchBar resignFirstResponder]; //[self dismissModalViewControllerAnimated:YES]; } - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { NSLog(@" searchBarCancelButtonClicked"); [searchBar resignFirstResponder]; shareItemName =newSearchBar.text; [self dismissModalViewControllerAnimated:YES]; } - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { NSLog(@"searchBarShouldBeginEditing"); [newSearchBar setShowsCancelButton:YES animated:YES]; return YES; }
These are my delegates for this
Please check my code and answer me. I need to enable the Cancel button when loading a view, and this action will revert to the previous view
I like it

Or how can I add another cancel button when the cancel button is activated. So that I can enable this.please, give me all the details
source share