Ios UISearchDisplayController-结果存在但不显示

Ios UISearchDisplayController-结果存在但不显示,ios,uisearchbardelegate,Ios,Uisearchbardelegate,我对UISearchDisplayController有奇怪的问题 我的代码如下: 行数部分: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if ([[self searchDisplayController] isActive]) { return [self.itemsFound count]; } else { return

我对
UISearchDisplayController
有奇怪的问题

我的代码如下:

行数部分:

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

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

  return [self.items count];
}
- (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];
}
- (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;
}
cellForRowAtIndexPath:

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

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

  return [self.items count];
}
- (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];
}
- (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;
}
下一步:

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

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

  return [self.items count];
}
- (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];
}
- (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;
}
应重新加载搜索字符串的表:

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

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

  return [self.items count];
}
- (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];
}
- (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;
}
我的桌子:

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

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

  return [self.items count];
}
- (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];
}
- (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;
}

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

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

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

我不知道为什么我不能在第二个屏幕上显示结果,而结果(显示在控制台上)

你知道吗

谢谢你抽出时间