I'm using the following inside a button click or (IBAction)
- (IBAction)HistoryBtn:(id)sender {
self startReport];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//============================
so some long processing code
//============================
[self stopReport];
});
}
Where
-(void) startReport
{
alert = [[UIAlertView alloc] initWithTitle:@"Generating PDF" message:@" " delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[alert setDelegate:self];
[progress startAnimating];
[alert show];
}
-(void) stopReport
{
NSLog(@" Stop Called ");
[self.alert dismissWithClickedButtonIndex:0 animated:NO];
self.alert = nil;
NSLog(@" Stop Called ");
}
The problem is The AlertView popups up and I can see the button work, then StopReport IS called But the AlertView stays there How can I get the AlertView to go away
Thanks in advance
You must work with the UI only on the main thread.
- (IBAction)HistoryBtn:(id)sender {
self startReport];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//============================
so some long processing code
//============================
dispatch_async(dispatch_get_main_queue(), ^{
[self stopReport];
});
});
}