Yesterday I added a UIActivityIndicatorView
to my iOS application and everything was fine, now I'm trying to run the same application but the UIActivityIndicatorView
is not showing anymore and the agenda
view (which calls the web service) takes very long time (more than yesterday) to appear and often it does not appear at all. How can I fix this problem, please? Here is my code:
- (IBAction)agenda:(id)sender {
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(160, 240);
spinner.hidesWhenStopped = YES;
[self.view addSubview:spinner];
[spinner startAnimating];
// how we stop refresh from freezing the main UI thread
dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);
dispatch_async(downloadQueue, ^{
// do our long running process here
// [NSThread sleepForTimeInterval:10];
AgendaViewController *agenda = [[ AgendaViewController alloc] initWithNibName:nil bundle:nil];
// do any UI stuff on the main UI thread
dispatch_async(dispatch_get_main_queue(), ^{
[spinner stopAnimating];
[self.navigationController pushViewController:agenda animated:YES];
});
});
dispatch_release(downloadQueue);
}