gpt4 book ai didi

iphone - UIAlertView 不解雇

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:14:45 25 4
gpt4 key购买 nike

我在单击按钮或 (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 被调用但是 AlertView 留在那里我怎样才能让 AlertView 消失

提前致谢

最佳答案

您只能在主线程上使用 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];
});
});
}

关于iphone - UIAlertView 不解雇,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11485990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com