title: Search Bar Cancel Button is Not Working
body: <p>My App is having a search bar for searching records from the table view,which is populated by sqlite DB.
  My problem is that when the view opens the "cancel" button is not enabled and also I cant touch on that, just like a image only.It is there but no action is with that.
  when we click on that search bar text the cancel button will be changed to "done" it is enabled one.
  so here is my code</p>
  
  <p>this is my search bar view,see that cancel button.It is not enabled</p>
  
  <p><img src="https://i.stack.imgur.com/0lLd0.png" alt="this is my search bar view.see that cancel button.It is not enabled"></p>
  
  <pre><code>- (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;
  }
  </code></pre>
  
  <p>These are my delegates for that</p>
  
  <p>Please check my code and give me the answer. I need to enable the "Cancel" button when the view is loaded and it action will be go back to previous view</p>
  
  <p>I need like this</p>
  
  <p><img src="https://i.stack.imgur.com/FkJvK.png" alt="enter image description here"></p>
  
  <p>Or else how can I add a another cancel button on exciting cancel button.so that I can enable that.please give me all the details </p>