Сгруппированная ячейка появляется в моем простом tableView, и я не знаю, почему - PullRequest
2 голосов
/ 12 августа 2011

Так что я не знаю, как это происходит, или как это исправить, но у меня проблема с plain tableView моего UISearchDisplayController, отображающего результаты поиска с сгруппированной ячейкой.

У меня есть массив dataSource с несколькими именами, массив tableData, который перебирает массив dataSource и добавляет любые записи, которые соответствуют searchText, а затем, в зависимости от того, какой это tableView, я перезагружаю tableView с соответствующим dataSource ...

У кого-нибудь есть идеи?

Код:

- (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;

   }

И тогда, когда поиск введен, соответствующие строки добавляются в массив tableData

Ответы [ 2 ]

1 голос
/ 12 августа 2011

присваивает теги UITableView и скрывает группированный tableView при поиске

0 голосов
/ 13 августа 2011

В документации для UISearchDisplayController о свойстве searchResultsTableView написано

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

Так что вы можете попробовать создать собственный UITableView при настройкеUISDC, явно разъясняя это:

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