shouldReloadTableForSearchString不显示过滤结果

时间:2010-10-27 07:04:16

标签: objective-c uisearchbar

我已经尝试了几个小时,但无法弄清楚为什么它没有显示过滤结果。它始终显示所有结果。我不确定我做错了什么。

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString scope:
  [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
    // Return YES to cause the search result table view to be reloaded.
    return YES;
}


- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
 /*
  Update the filtered array based on the search text and scope.
  */

 [self.filteredListContent removeAllObjects]; // First clear the filtered array.
    //for loop here
 NSLog(@"%i", [filteredListContent count]);
   //filteredListContent contains correct number of filtered items
}

1 个答案:

答案 0 :(得分:1)

有效。我没有在numberOfRowsInSection方法

中使用过滤结果数组
was:
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
            return [self.persons count];
    }


changed to:
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        if (tableView == self.searchDisplayController.searchResultsTableView)
        {
            return [self.filteredListContent count];
        }
        else
        {
            return [self.persons count];
        }
    }