Indexed search in a UIViewController! At any letters inserted into the textfield research, a method is called that executes a database query to obtain tuples as a function of string. If I write a letter after letter, the app crashes because the method is called again while it is still running. Instead, if I write a letter, look forward to the completion of the dispatch queue and write another letter, everything works! But I would like to perform as described in the first case! Here the code:
- (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];
});
});
}
}
Is there a solution to conduct research in a manner similar to the facebook/google search engine? Given that I don't use UISearchDisplayController, but I just use a textfield that calls the method searchUser every [Editing Did Change] and it filled the Tableview with all results! Please help me!