0

我有一个方法refreshDataAction

- (void)refreshDataAction
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"Loading Data.Please Wait";
    [self deletePreviousValues];
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        NSLog(@"Getting customer values");
        [self getAllCustomerValues];
        NSLog(@"Got customer values");

        NSError *nwerror = nil;
        if (![self.secondMOC save:&nwerror])
        {
            NSLog(@"209 Failed to save second MOC");
        }
        else
        {
            //NSLog(@"saved success");
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        });
        NSLog(@"Saved");
    });

    NSLog(@"Dispatched");   
}

所以一旦refreshDataAction开始我应该看到HUD。但它不像在显示 HUD 之前等待 13 秒。我不知道为什么会这样。我尝试了不同的方法,如 ActivityIndi​​cator,但无济于事。为什么我的应用程序要等待 13 秒才能启动 hud。在模拟器上它的瞬间。我点击按钮,我看到了HUD。但在设备上延迟 13 秒。在后台线程做一些工作时立即启动 hud。请帮忙。花了整整 5 个小时想办法完成这项任务。

这里有我的问题:UIAlertview hang while the thread in background is loading data

我把它改成了MBProgressHUD. 可能一些与之合作过的开发人员MBProgressHUD可能会看到这个问题。

我的主 UI 线程是否处于某种睡眠模式 13 秒?我现在真的不知道。仅供参考,它在 iOS 6.0 中。这是一个内部 iPad 应用程序。如果您需要更多信息,请询问。谢谢

4

1 回答 1

0

我会将以下内容添加到您的 viewDidLoad 中。

HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = @"";
HUD.mode = MBProgressHUDModeIndeterminate;

然后,您可以简单地调用以下方法而无需 dispatch_get_main_queue()。

[HUD show:YES];

和...

[HUD hide:YES];
于 2013-02-21T22:42:18.890 回答