【发布时间】:2014-04-15 11:08:07
【问题描述】:
UIViewController 中的索引搜索!在插入到文本字段研究中的任何字母处,都会调用一种方法,该方法执行数据库查询以获取作为字符串函数的元组。 如果我一个接一个地写信,应用程序会崩溃,因为该方法仍在运行时再次调用。 相反,如果我写一封信,期待调度队列的完成并再写一封信,一切正常!但我想按照第一种情况执行! 代码如下:
- (IBAction)searchUser:(id)sender{
dispatch_async(dispatch_get_main_queue(), ^{
[_arrID removeAllObjects];
[_arrNames removeAllObjects];
[_arrPictures removeAllObjects];
[self.tableView reloadData];
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
dispatch_async(dispatch_get_main_queue(), ^{
CGRect activityFrame = CGRectMake(self.view.center.x, self.view.center.y, 0.0, 0.0);
_activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:activityFrame];
[[self.view superview] addSubview:_activityIndicator];
_activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
_activityIndicator.color = [UIColor whiteColor];
[_activityIndicator startAnimating];
});
//Here I fill the 3 arrays with details obtained from external queries on database
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[_activityIndicator stopAnimating];
});
});
}
}
是否有解决方案以类似于 facebook/google 搜索引擎的方式进行研究?鉴于我不使用 UISearchDisplayController,但我只使用了一个文本字段,它在每个 [Editing Did Change] 调用方法 searchUser 并且它用所有结果填充了 Tableview!请帮帮我!
【问题讨论】:
-
我提交了我的示例代码,它对我来说可以正常工作,你可以为自己定制代码
标签: ios objective-c uitableview grand-central-dispatch dispatch