[英]Make iOS not to wait until the entire method is finished to start animation
我有一个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。 但是,没有像等待13秒才能显示HUD的样子。 我不知道为什么会这样发生。 我尝试了类似ActivityIndicator的尝试,但无济于事。 为什么我的应用程序等待13秒才能启动hud。 在模拟器上即时。 我单击按钮,然后看到HUD。 但是在设备上延迟了13秒。 当后台线程正在执行某些工作时,请立即启动hud。 请帮忙。 花费了整整5个小时的时间来弄清楚执行此任务的方法。
我的问题在这里: UIAlertview在后台线程正在加载数据时挂起
我将其更改为MBProgressHUD
。 也许某些使用MBProgressHUD
开发人员可以看到此问题。
我的主UI线程是否处于某种睡眠模式13秒钟? 我真的不知道这一点。 仅供参考,它在iOS 6.0中。 这是一个内部iPad应用程序。 如果您需要更多信息,请询问。
我将以下内容添加到您的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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.