title: Custom Searchbar in iOS
body: <p>Hello i am using <code>UISerchbar</code> in <code>tableview</code> but is there any easy way to create custom <code>searchbar</code>  in <code>tableview headerview</code>?</p>
  
  <p>i already check below link but i am not understand.</p>
  
  <p><a href="https://stackoverflow.com/questions/25904213/custom-uisearchbar-with-uisearchcontroller">Custom UISearchBar with UISearchController</a></p>
  
  <p><a href="https://stackoverflow.com/questions/18719517/how-do-i-use-the-uisearchbar-and-uisearchdisplaycontroller">How do I use the UISearchBar and UISearchDisplayController</a></p>
  
  <p>I have added searchDisplayController : : 
  <a href="https://i.stack.imgur.com/FugGW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FugGW.png" alt="enter image description here"></a></p>
  
  <p>And This is my code for searchController,</p>
  
  <pre><code>    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
      self.searchController.searchResultsUpdater = self;
      self.searchController.dimsBackgroundDuringPresentation = NO;
      self.searchController.searchBar.delegate = self;
      self.definesPresentationContext = YES;
      [self.searchController.searchBar setBarTintColor:[UIColor darkGrayColor]];
      self.tableView.tableHeaderView = self.searchController.searchBar;
  </code></pre>
  
  <p>I have set delegate for <code>UISearchBarDelegate,UISearchResultsUpdating</code> as well,</p>
  
  <p>and implemented their method ,</p>
  
  <pre><code>    - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
  {
      if (_searchController.isActive &amp;&amp; _searchController.searchBar.text.length &gt;0){
  
          NSPredicate *resultPredicate = [NSPredicate
                                          predicateWithFormat:@"SELF.name contains[cd] %@",
                                          searchText];
  
          abcd = [sortedEventArray  filteredArrayUsingPredicate:resultPredicate];
          NSLog(@"%@",searchResults);
  
      }
  
  
  }
  
  - (void)updateSearchResultsForSearchController:(UISearchController *)searchController1
  {
      NSString *searchString = searchController1.searchBar.text;
      [self filterContentForSearchText:searchString scope:@"abc"];
      //[self filterContentForSearchText:searchString :@"abc"];
      [self.tableView reloadData];
  }
  </code></pre>
  
  <p>cancel button event</p>
  
  <pre><code>    - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
  {
        abcd=[sortedEventArray mutableCopy];
        [_tableView reloadData];
  
  }
  
  
  
     -(void)delete{
  
  
      NSManagedObjectContext *context = [self managedObjectContext];
      NSFetchRequest * allMovies = [[NSFetchRequest alloc] init];
      [allMovies setEntity:[NSEntityDescription entityForName:@"Data" inManagedObjectContext:context]];
      [allMovies setIncludesPropertyValues:NO]; //only fetch the managedObjectID
  
      NSError * error = nil;
      NSArray * movies = [context executeFetchRequest:allMovies error:&amp;error];
      //error handling goes here
      for (NSManagedObject * movie in movies) {
          [context deleteObject:movie];
      }
      NSError *saveError = nil;
      [context save:&amp;saveError];
  }
  </code></pre>
  
  <p>Still Its not working</p>
  
  <p>Thanks in advance :)</p>