Я пытаюсь отобразить сообщение о том, что результаты не найдены, когда извлеченный контроллер результатов не возвращает строк как здесь .
Для этого я помещаю код в метод numberOfRows. Тем не менее, это исключение. Вот мой код:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.searchDisplayController.searchResultsTableView) {
return [searchResults count];
} else {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections]objectAtIndex:section];
int numRows =[sectionInfo numberOfObjects];
if (numRows>=1) {
return [sectionInfo numberOfObjects];
}
else {
UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
messageLabel.text = @"No comments yet.";
messageLabel.textColor = [UIColor grayColor];
messageLabel.numberOfLines = 0;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
return 0;
}
}
Должен ли я поместить этот код в другом месте? Или что может быть не так с этим, что может вызвать исключение.
Заранее спасибо за любые предложения.