Search code examples
iphoneipaduisearchdisplaycontrolleruitableview

A grouped cell is showing up in my plain tableView and I don't know why


So I don't know how this is happening, or how to fix it, but I am having an issue of my UISearchDisplayController's plain tableView displaying search results with a grouped cell.

I have a dataSource array with a few names, a tableData array that iterates through the dataSource array and adds any entries that fit the searchText, and then depending on which tableView it is, I reload the tableView with the appropriate dataSource...

Ideas anyone?

Code:

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
     int count = 0;

     if(aTableView == self.tableView){
        count = [userTableData count]==0?1:[userTableData count];
     }else{
            count = [tableData count];
     }
     return count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return @"Users"; 
}

- (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CellIdentifier";

// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    cell.accessoryType = UITableViewCellAccessoryNone;
}

if(tView == self.tableView){
    if([userTableData count] == 0){
        cell.textLabel.text = @"Please select a user";
    }else{
        cell.textLabel.text = [userTableData objectAtIndex:indexPath.row];
    }
}else{
    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
}

return cell;

   }

And then as the search is entered, matching strings are added to the tableData array


Solution

  • In the documentation for UISearchDisplayController about the searchResultsTableView property, it says

    Discussion: This method creates a new table view if one does not already exist.

    So what you could try is create your own UITableViewwhen you set up the UISDC, explicitly making it plain:

    UITableView *searchTableView = [[UITableView alloc] initWithFrame:CGRectZero 
        style:UITableViewStylePlain];
    searchDisplayController.searchResultsTableView = searchTableView;