I am creating an application that retrieves a result set from a database - I use MBProgressHUD to show the progress of the query with animation. The method I use calls the animation when the method runs on another thread, and after that it hides the animation. My question, after the call:
[HUD showWhileExecuting:@selector(getResults) onTarget:self withObject:nil animated:YES];
I would like, if there are no results, to display a warning that states this, and if so, download the following view. So far I have this code:
[HUD showWhileExecuting:@selector(getResults) onTarget:self withObject:nil animated:YES]; if(self.thereAreEvents) { [self performSegueWithIdentifier:@"searchResults" sender:self]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No results" message:@"Sorry, there are no results for your search. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show]; [alert release]; }
self.thereAreEvents
set at the end of the getResults
method. However, since this method is called on another thread, this execution line continues and displays a warning, even if there are events in the database.
So, I have two questions: what is the easiest way to implement the wait mechanism in iOS and what is the most efficient way to implement this mechanism in iOS?
Thanks!
source share