У меня есть табличный вид с контроллером отображения поиска. Когда я печатаю поиск, журнал показывает, что поиск работает и правильно фильтруется, однако на экране отображается только «Нет результатов». Я использую Core Data, если это имеет значение.Результаты поиска не отображаются
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
}
else{
return[[self.fetchedResultsController sections]count];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections]objectAtIndex:section];\
return [secInfo numberOfObjects];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
static NSString *CellIdentifier = @"Cell";
if (tableView != self.tableView) {
NSLog(@"Found searchDisplayController");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
} else {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSLog(@"Found regular table View");
}
// Configure the cell...
Instance *instance = [self.fetchedResultsController objectAtIndexPath:indexPath];
if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text = [searchResults objectAtIndex:indexPath.row];
} else {
cell.textLabel.text = instance.name;
}
Вот NumberOfRowsInSection и номер:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
}
else{
return[[self.fetchedResultsController sections]count];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections]objectAtIndex:section];\
return [secInfo numberOfObjects];
}
где вы обновляете содержимое ячейки? – Max
Ниже: Экземпляр * instance = [self.fetchedResultsController objectAtIndexPath: indexPath]; // больше данных поиска if (tableView == self.searchDisplayController.searchResultsTableView) { cell.textLabel.text = [searchResults objectAtIndex: indexPath.row]; } else { cell.textLabel.text = имя экземпляра; } – Isaac
@ Исаак: Можете ли вы добавить этот код к своему вопросу? Это облегчает чтение. - Методы 'numberOfSections' и' numberOfRowsInSection' также будут полезны. –