我在我们的教学应用程序中使用 MBProgressHUD,它是通过标签栏导航的。
用户将通过 Urban Airship 的店面从 tableview 直接进入 UA 详细视图。单击购买后,我会使用 HUD
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[self.view.window addSubview:HUD];
它正在使用showWhileExecuting语句。
它通过三个while语句从“连接”变为“下载”到“解包”。一切正常。
问题来了......我第二次这样做标签文本不会改变。它卡在“正在连接”上。我可以在 NSLog 中看到它正在经历其他循环。
最重要的是,如果我尝试更改模式,应用程序会崩溃。
这只会发生第二次,以及任何后续使用。如果我杀死该应用程序,一切都会第一次再次运行。
在我看来,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;
}