Hi All I have an issue here that I'm hoping somebody can help out with... I have an app with a search button, when a user performs a search I want to resign the keyboard and display a "searching graphic" but for some reason the way I am doing it is apparently not thread safe. Is there something I'm missing here ?
Code:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
dispatch_queue_t coreDataThread = dispatch_queue_create("com.me.coreDataThread", DISPATCH_QUEUE_SERIAL);
dispatch_sync(coreDataThread, ^{
self.activityIndicatorView = [self loadingView];
self.activityIndicatorView.center = CGPointMake(self.view.frame.size.width /2, self.view.frame.size.height /2);
dispatch_async(dispatch_get_main_queue(), ^{
[self.view addSubview:self.activityIndicatorView];
[self.view addSubview:activityIndicatorView];
[self.searchBar resignFirstResponder];
});
});
//---------------------\\
dispatch_sync(coreDataThread, ^{
[self getNewDataAfterFirstResponderResigned];
[self removeActivityIndicator];
});
dispatch_release(coreDataThread);
}
I am dispatching the threads synchronously because I want to create and display the spinner, as well as remove the keyboard first, then Execute the db search.....
Thanks for the time