SearchBar在点击取消按钮之前不显示结果 [英] SearchBar not displaying results until cancel button clicked

查看:142
本文介绍了SearchBar在点击取消按钮之前不显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用搜索栏(和搜索显示)实现了一个UITableView - 一切正常,但在点击搜索栏取消按钮之前,表格结果不会更新。

I have implemented a UITableView with search bar (and search display) - all works fine, but the table results do not get updated until the search bar cancel button is tapped.

委托方法:

- (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;
}

我是否需要在从服务器接收数据后调用委托方法?或者我应该同步请求吗?

Do I need to call a delegate method after receiving the data from the server? Or should I make the request synchronous?

谢谢

编辑:我试过一个同步请求,它仍然无法正常工作!

edit: I tried with a synchronous request and it still does not work!

推荐答案

通过将此代码添加到最后解决了这个问题我的getProductData方法:

Resolved this issue by adding this code to the end of my getProductData method:

[[[self searchDisplayController] searchResultsTableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

这篇关于SearchBar在点击取消按钮之前不显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆