iOS - UIAlertView 被提前解雇

发布于 2024-11-30 04:02:42 字数 1627 浏览 0 评论 0原文

我有一个视图,除其他外,它上面还有一个按钮。当用户按下按钮时,将执行以下代码:

- (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];
    });
}

大多数情况下,整个异步代码都会运行,从而消除警报消息。然而,在警报消息消失后​​,屏幕仍然保持冻结状态大约 2 或 3 秒,然后再推送到下一个 viewController (photoViewControllerView)。我不知道为什么会发生这种情况。我希望警报消息在需要时持续存在。有什么想法吗?

先感谢您!

I have a view and, among other things, a button on it. When the user pushes the button, the following code is executed:

- (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];
    });
}

What happens is that, most of the time, the whole asynchronous code runs, dismissing the alert message. However, after the alert message is dismissed, the screen still stays frozen for about 2 or 3 seconds before it pushes to the next viewController (photoViewControllerView). I have no idea why that is happening. I want the alert message to stay on as long as needed. Any ideas?

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软糖 2024-12-07 04:02:42

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

- (void)viewWillAppear:(BOOL)animated

So to me, it sounds like the problem is the PhotoViewController is taking time to load (can you use Instruments to confirm?). Since PhotoViewController is your own class, you could have it have a delegate, make the main view controller (the one that dismisses the UIAlert) the delegate of PhotoViewController instance, and have the PhotoViewController call the delegate to inform it when it's ready and/or visible, for example at the end of

- (void)viewWillAppear:(BOOL)animated
野鹿林 2024-12-07 04:02:42

您应该只呈现一个警报视图并将 self 指定为它的委托人,然后当您收到通知警报视图被解除时(通过 alertView:didDismissWithButtonIndex: 委托方法),执行其余代码。

You should just present an alert view and assign self as it's delegate, then when you get informed that alert view is dismissed (via alertView:didDismissWithButtonIndex: delegate method), execute the rest of your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文