gpt4 book ai didi

objective-c - iOS - UIAlertView 在预期之前被关闭

转载 作者:行者123 更新时间:2023-11-29 11:21:09 26 4
gpt4 key购买 nike

我有一个 View ,其中还有一个按钮。当用户按下按钮时,将执行以下代码:

- (IBAction) goToPhotoViewControllerView:(id) sender{

alert = [[UIAlertView alloc] initWithTitle:@"Por favor, aguarde" message:@"Carregando imagens"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
[alert show];

if(alert != nil) {
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

indicator.center = CGPointMake(alert.bounds.size.width/2, alert.bounds.size.height-45);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
}

dispatch_async(dispatch_get_global_queue(0, 0), ^{

//Do a lot of stuff here

PhotoViewController *photoViewControllerView = [[PhotoViewController alloc] initWithNibName:@"PhotoViewController" bundle:nil];

[iosDao selectComics];

[photoViewControllerView startWithComic:[[iosDao.comics lastObject] idComic] numPanels:[[[iosDao.comics lastObject] panels] count]];
photoViewControllerView.navigationItem.title = @"Comics";

[iosDao release];
[[self navigationController] pushViewController:photoViewControllerView animated:YES];

[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
});
}

实际情况是,大多数时候,整个异步代码都在运行,并消除了警报消息。但是,在警报消息消失后​​,屏幕在推送到下一个 viewController (photoViewControllerView) 之前仍会卡住大约 2 或 3 秒。我不知道为什么会这样。我希望警报消息在需要时一直显示。有什么想法吗?

提前致谢!

最佳答案

所以对我来说,听起来问题是 PhotoViewController 需要时间来加载(您可以使用 Instruments 来确认吗?)。由于 PhotoViewController 是你自己的类,你可以让它有一个委托(delegate),使主视图 Controller (解除 UIAlert 的那个)成为 PhotoViewController 实例的委托(delegate),并让 PhotoViewController 在准备好和/或时调用委托(delegate)通知它可见,例如在

的末尾
- (void)viewWillAppear:(BOOL)animated

关于objective-c - iOS - UIAlertView 在预期之前被关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7082679/

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