モーダル ビューが閉じられるたびに、@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 を更新するにはどうすればよいですか? あなたの応答は大歓迎です。