I have a UISearchBar and UISearchDisplayController. When the user writes text in it inside searchBar:textDidChange: I make a web-service call to filter my TableView. The problem is that the GUI get unresponsive until I get the result from the web-service. I’ve tried to solve it using [self performSelector:@selector(callWebService:) withObject:searchText];, but it’s still unresponsive.
EDIT: Following Flink advice, I changed performSelector to performSelectorInBackground, but now the tableView doesn’t filter correctly, it only show ‘No Results’.
even tableView:numberOfRowsInSection: isn’t get called.
EDIT Again: The reason I got ‘No Results’ was due to not calling reloadData on the correct tableView. UISearchDisplayController has a property named searchResultsTableView. So in the end what I used was [self.searchDisplayController.searchResultsTableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:false]; and now it works fine.
It should be noted that although I chose the performSelectorInBackground, I probably should have tried to use sendAsynchronousRequest method on NSURLConnection – See AliSoftware’s answer.
You need to make your web call async.
http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial
In your case, you can change
performSelectortoperformSelectorInBackground