UISearchDisplayController - 结果存在但不显示

时间:2015-11-27 13:41:27

标签: ios uisearchbardelegate

我对UISearchDisplayController感到奇怪。

我的代码如下:

numberOfRowsInSection:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  if ([[self searchDisplayController] isActive])
  {
    return [self.itemsFound count];

  } else {
    return [self.items count];
  }

  return [self.items count];
}

的cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  FavouriteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  if (!cell)
  {
    cell = [[FavouriteTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  }

  Facilities *f = nil;

  if ([[self searchDisplayController] isActive])
  {
    f = [self.itemsFound objectAtIndex:indexPath.row];

  } else {
    f = [self.items objectAtIndex:indexPath.row];
  }

  [cell.favouriteButton addTarget:self action:@selector(toggleFavourite:) forControlEvents:UIControlEventTouchUpInside];
  [cell.titleLabel setText:f.name];

  return cell;
}

下一步:

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
  NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@",searchText];

  self.itemsFound              = [self.items filteredArrayUsingPredicate:resultPredicate];
}

shouldReloadTableForSearchString:

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {

  self.itemsFound = nil;

  [self filterContentForSearchText:searchString
                           scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                  objectAtIndex:  [self.searchDisplayController.searchBar
                                                 selectedScopeButtonIndex]]];
  return YES;
}

我的表:

table

如果我输入列表中的字母:

after typing letter a

结果存在但未显示在列表中。

在下一张图片上没有结果,屏幕显示正确的信息。

no results

我不知道为什么在结果显示(显示在控制台上)时无法在第二个屏幕上显示结果。

你有什么想法吗?

感谢您的时间。

0 个答案:

没有答案