2014-11-01 4 views
0

я получаю следующее сообщение об ошибке, когда я начала введите искомый текст в SearchBarПолучение «отказ Assertion» в UISearchResultsTableView

Assertion failure in -[UISearchResultsTableView _configureCellForDisplay:forIndexPath:] 

Мой cellForRowAtIndexPath код Search Display Controller выглядит следующим образом:

if(tableView == self.searchDisplayController.searchResultsTableView) 
{ 
    static NSString *CellIdentifier = @"cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if(cell == nil) 
    { 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    } 

    cell.textLabel.text = [search objectAtIndex:indexPath.row]; 

    return cell; 
} 

ответ

4

Заменить ваш код с этим может быть, он будет работать.

if(tableView == self.searchDisplayController.searchResultsTableView) 
{ 
    static NSString *CellIdentifier = @"cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if(cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:CellIdentifier]; 
    } 

    cell.textLabel.text = [search objectAtIndex:indexPath.row]; 

    return cell; 
} 

, потому что, как только вы обнаружите, что объект ячейки равен нулю вы снова выделяем ячейку с объектом ноль с помощью [tableView dequeueReusableCellWithIdentifier:CellIdentifier];, поэтому он не работает.

+0

Спасибо большое :) –

+0

Что делать, если я хочу использовать пользовательскую ячейку? –

+0

У меня нет пользовательского файла XIB по-другому –

Смежные вопросы