我在按钮单击或(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];
});
}
其中
-(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 ");
}
问题是AlertView弹出,我可以看到按钮工作,然后调用StopReport IS但是AlertView停留在那里我怎样才能让AlertView消失
提前致谢
答案 0 :(得分:3)
您必须仅在主线程上使用UI。
- (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];
});
});
}