タブバーでナビゲートされる教育アプリで MBProgressHUD を使用しています。
ユーザーは、Urban Airship のストアフロントを介してテーブルビューから UA の詳細ビューに直接移動します。購入をクリックすると、HUD が表示されます
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[self.view.window addSubview:HUD];
showWhileExecutingステートメントを使用しています。
"Connecting" から "Downloading" から "Unpacking" に変わるには、3 つの while ステートメントが必要です。すべて正常に動作しています。
ここで問題が発生します...これを2回目にすると、ラベルのテキストは変更されません。「接続中」で止まっています。NSLog で、他のループを通過していることがわかります。
その上、モードを変更しようとすると、アプリがクラッシュします。
これは 2 回目以降の使用時にのみ発生します。アプリを強制終了すると、すべてが初めて機能します。
MBProgressHUD が終了してもリセットされないように見えます。
(ARCはプロジェクトで使用されています)
解決策を持っている人はいますか?ありがとう
編集:
- (void)showWithLabelDeterminate
{
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
HUD.mode = MBProgressHUDModeIndeterminate;
[self.view.window addSubview:HUD];
HUD.delegate = self;
HUD.labelText = NSLocalizedString(@"Connecting","");
HUD.detailsLabelText = @" ";
HUD.minSize = CGSizeMake(145.f, 145.f);
HUD.dimBackground = YES;
[HUD showWhileExecuting:@selector(lessonDownloadProgress) onTarget:self withObject:nil animated:YES];
}
-(void)lessonDownloadProgress
{
DataManager *sharedManager = [DataManager sharedManager];
// HUD.mode = MBProgressHUDModeIndeterminate;
HUD.labelText = nil;
HUD.detailsLabelText = nil;
while ([sharedManager.downHUD floatValue] == 0.0f)
{
[self parentViewController];
NSLog(@"HUD lessonDownloadProgress: %f", HUD.progress);
HUD.labelText = NSLocalizedString(@"Connecting","");
HUD.detailsLabelText = @" ";
NSLog(@"Waiting for download to start");
// Wait for download to start
usleep(80000);
}
// Switch to determinate mode
// HUD.mode = MBProgressHUDModeDeterminate;
HUD.labelText = NSLocalizedString(@"DownLoading","");
HUD.progress = [sharedManager.downHUD floatValue];
while (HUD.progress < 1.0f && [sharedManager.cleanedUp isEqualToString:@"No"])
{
// [self parentViewController];
HUD.labelText = NSLocalizedString(@"Downloading","");
NSLog(@"HUD lessonDownloadProgress: %f", HUD.progress);
HUD.progress = [sharedManager.downHUD floatValue];
NSString *percent = [NSString stringWithFormat:@"%.0f", HUD.progress/1*100];
HUD.detailsLabelText = [percent stringByAppendingString:@"%"];
usleep(50000);
}
// Switch HUD while cleanUp
HUD.mode = MBProgressHUDModeIndeterminate;
while ([sharedManager.cleanedUp isEqualToString:@"No"])
{
[self parentViewController];
HUD.labelText = NSLocalizedString(@"Unpacking","");
HUD.detailsLabelText = @" ";
// wait for cleanup
NSLog(@"Waiting for clean up");
usleep(50000);
}
NSLog(@"++ Finished loops ++");
NSLog(@"Finished HUD lessonDownloadProgress: %f", HUD.progress);
[MBProgressHUD hideHUDForView:self.view animated:YES];
[HUD removeFromSuperview];
HUD.delegate = nil;
[HUD release];
HUD = nil;
}