title: Search Bar and Search Display Controller in table view
body: <p>I have tried to implement a search bar but I have not had any luck dealing with this problem. I would really appreciate any help that can be provided. I've a big project in which I've a table view, and I want to implement a search bar over it and see the real time filtering. I do not use Storyboard but I'm using XIB. I've added the following protocols:</p>
  
  <pre><code>&lt;UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,UISearchDisplayDelegate&gt;
  </code></pre>
  
  <p>I've declared 2 arrays in @interface , the first for the whole elements and the second one for the filtered ones:</p>
  
  <pre><code>    NSArray*     OldList;
      NSArray*     filteredList;
  </code></pre>
  
  <p>Then I've setted the number of rows and the number of sections and then:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      myClassCell *cell = [tableView dequeueReusableCellWithIdentifier:MYCELLCLASS];
      if (cell == nil)
      {
          cell = [myClassCell newFromNib];
      }
      NSMutableDictionary* elem = nil;
      if (tableView == self.searchDisplayController.searchResultsTableView)
      {
          elem = [filteredList objectAtIndex:indexPath.row];
          if ([elem count]+1 &gt; indexPath.row)
              [cell showValues:elem];
          else
              [cell showValues:nil];
      }
      else
      {
          elem = [OldList objectAtIndex:indexPath.row];
          if ([elem count]+1 &gt; indexPath.row) 
              [cell showValues:elem];
          else
              [cell showValues:nil];
      }
      return cell;
  }
  
  -(void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
  {
      NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
      filteredist = [OldList filteredArrayUsingPredicate:resultPredicate];
  }
  
  -(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
  {
      [self filterContentForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
      objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
      return YES;
  }
  </code></pre>
  
  <p>At this point, I haven't done any changes to the xib, no links and no other stuffs. If I compile I get my table, but obviously if I try to search something, nothing works. Moreover if I scroll down to the end of the table the app crashes. The real problem is that I can't see the search bar working. Could someone help me please?</p>