我已经实现了带有搜索栏(和搜索显示)的 UITableView - 一切正常,但在点击搜索栏取消按钮之前,表格结果不会更新。
委托(delegate)方法:
- (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;
}
从服务器接收到数据后是否需要调用委托(delegate)方法?或者我应该使请求同步?
谢谢
编辑:我尝试了同步请求,但仍然不起作用!
最佳答案
通过将此代码添加到我的 getProductData 方法的末尾解决了此问题:
[[[self searchDisplayController] searchResultsTableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
关于iphone - 在单击取消按钮之前,搜索栏不会显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4042111/