每次关闭模态视图时,我都会在@interface ZxBancaD:UITableViewController中出现一个MBProgressHUD
- (void) disparaMa:(NSNotification *)notification {
hudX = [MBProgressHUD showHUDAddedTo:self.splitViewController.view animated:YES];
hudX.delegate = self;
hudX.mode = MBProgressHUDModeAnnularDeterminate;
hudX.labelText = @"Pago Minimo...";
hudX.dimBackground = YES;
[hudX showWhileExecuting:@selector(actEtiqueta) onTarget:self withObject:nil animated:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^ (void) {
[self miniAutomatico];
});
}
我使用此方法更新我的hudX
- (void) actEtiqueta {
xP = 0.0f;
while (xP < 1) {
xT = [[NSUserDefaults standardUserDefaults] integerForKey:kVueltas];
xP = ((double)xT)/24;
hudX.detailsLabelText = [NSString stringWithFormat:@"Vuelta%i", xT];
hudX.progress = xP;
NSLog(@"AxTiempoB.actEtiqueta.progress %f | xP %f | xT %i", hudX.progress, xP, xT);
usleep(50000);
}
}
后台进程是(此处计算xT变量):
- (void) miniAutomatico {
cwMonitorBz = [[[CwMonitorBz alloc] init]autorelease];
cwMonitorBz.persistentStoreCoordinator = self.persistentStoreCoordinator;
cwMonitorBz.managedObjectContextp = self.managedObjectContextp;
cwMonitorBz.gmCuenta = gmCuenta;
cwMonitorBz.esCuentaCero = @"1";
[self.cwMonitorBz monitorMinimoAuto];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"acabo..miniAutomatico");
[MBProgressHUD hideHUDForView:self.splitViewController.view animated:YES];
});
}
由于某种原因,hudX不会动态更新(实时)。它显示正确的值:(int)来自后台进程的XT,但是滞后。我猜我的主线程(UI)被阻止,但我不知道为什么或在哪里。
如何在真实领域(UI)上更新我的hudX?非常感谢您的回复。