我已经使用搜索栏(和搜索显示)实现了一个UITableView - 一切正常,但在点击搜索栏取消按钮之前,表结果不会更新。
委托方法:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
// asynchronous request with [self.tableView reloadData] in the connectionDidFinishLoading
[self getProductData:searchBar.text];
[searchBar resignFirstResponder];
[self.tableView reloadData];
}
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
}
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
return YES;
}
我是否需要在从服务器接收数据后调用委托方法?或者我应该使请求同步吗?
由于
编辑:我尝试过同步请求,但仍然无效!
答案 0 :(得分:4)
通过将此代码添加到getProductData方法的末尾解决了此问题:
[[[self searchDisplayController] searchResultsTableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
答案 1 :(得分:0)
我认为你必须实施:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
并返回YES
请参阅TableSearch示例代码
答案 2 :(得分:0)
请尝试这样的事情:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
[self getProductData:searchText];
[self.tableView reloadData];
}