【问题标题】:SearchBarDisplay Controller & Custome TableViewCell ExampleSearchBarDisplay 控制器和自定义 TableViewCell 示例
【发布时间】:2012-12-28 21:52:12
【问题描述】:

我真的不知道我做错了什么。我已经尝试了为我的表实现 SearchDisplayController 的不同版本,但它仍然无法正常工作。一切似乎都很好。回显出使用过的数组计数等值给了我正确的数字。甚至搜索部分也可以,因为我什至可以回显找到的字符串。唯一的问题是找到的结果没有显示在我的桌子上。一旦通过在搜索栏文本字段中输入开始输入,就会出现一个带有空行的黑白表格。我不知何故真的很沮丧,因为这已经花了两天时间。任何提示?

这是执行搜索的代码: -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

if(searchText.length == 0)
{
    isFiltered = FALSE;
}
else
{
    isFiltered = TRUE;

    if (filteredTableData == nil)
        filteredTableData = [[NSMutableArray alloc] init];
    else 
        [filteredTableData removeAllObjects];

    for (NSDictionary *d in self.countries)
    {
        NSString *strData = [d valueForKey:@"cname"];
        NSRange nameRange = [strData rangeOfString:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch)];
        if(nameRange.location != NSNotFound)
        {
            [filteredTableData addObject:d];
        }
    }
}
[self.tableView reloadData];

}

【问题讨论】:

    标签: ios


    【解决方案1】:

    如果您使用的是 UISearchDisplayController,则需要这样调用:

    [self.searchDisplayController.searchResultsTableView reloadData];
    

    而不是

    [self.tableView reloadData];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多