iphone - 在单击取消按钮之前,搜索栏不会显示结果

标签 iphone objective-c search uitableview uisearchbar

我已经实现了带有搜索栏(和搜索显示)的 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/

相关文章:

iphone - 来自文件问题的UIImage

iphone - 当我返回我的应用程序而不检查状态栏框架时,我如何知道电话何时在通话中?

ios - 如何处理搜寻字词中的空格

javascript - node.js 如何在字符串中搜索数组中的值

iphone - 停止 performSelector : from being performed

iphone - 如何在后台iphone中定期调用webservice?

ios - 为 UITableView 设置背景图像会占用内存并卡住应用程序

ios - 使用 UIBezierPath 绘制圆弧段

iphone - 如何修复 uiview 中 uilabel 的文本编码

php - 存储php mysql ajax搜索引擎结果