在我的应用程序中,我正在加载一个资源密集型视图,该视图需要大约1-2秒才能加载。所以我将其加载到这样的单独线程中:
hud = [[MBProgressHUD alloc] init];
[hud showWhileExecuting:@selector(loadWorkbench:) onTarget:self withObject:nil animated:YES];
但是,它永远不会出现,并且应用程序对于最终用户而言似乎是冻结的。有什么想法我做错了吗?
最佳答案
是。因为您从不告诉将HUD添加为窗口的子视图,所以它不会出现。尝试类似的东西:
// Should be initialized with the windows frame so the HUD disables all user input by covering the entire screen
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
// Add HUD to screen
[self.view.window addSubview:HUD];
// Register for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;
HUD.labelText = NSLocalizedString(@"Loading Workbench", nil);
HUD.detailsLabelText = NSLocalizedString(@"please wait", nil);
// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(loadWorkbench:) onTarget:self withObject:nil animated:YES];
由于您将自己设置为HUD委托,因此还添加以下委托方法:
- (void)hudWasHidden {
// Remove HUD from screen
[HUD removeFromSuperview];
// add here the code you may need
}
并记住在相应的头文件中添加
MBProgressHUDDelegate
。关于iphone - MBProgressHUD未显示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5522079/