MBProgressHUD not showing(MBProgressHUD 未显示)
问题描述
在我的应用程序中,我正在加载一个资源繁重的视图,加载大约需要 1 到 2 秒.所以我将它加载到一个单独的线程中,如下所示:
In my app, I am loading a resource heavy view that takes about 1 to 2 seconds to load. So I am loading it in a separate thread like this:
hud = [[MBProgressHUD alloc] init];
[hud showWhileExecuting:@selector(loadWorkbench:) onTarget:self withObject:nil animated:YES];
但它从未出现,并且应用程序在最终用户看来是冻结的.有什么想法我哪里出错了吗?
however it never appears, and application looks frozen to the end user. any ideas where I have gone wrong?
推荐答案
是的.它不会出现,因为您从未告诉将 HUD 添加为窗口的子视图.尝试类似:
Yes. It does not appear because you never tell add the HUD as a subview of the window. try something like:
// 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 委托,因此还要添加以下委托方法:
Since you are setting yourself as the HUD delegate, also add the following delegate method:
- (void)hudWasHidden {
// Remove HUD from screen
[HUD removeFromSuperview];
// add here the code you may need
}
记得在相应的头文件中添加MBProgressHUDDelegate.
and remember to add MBProgressHUDDelegate in the corresponding header file.
这篇关于MBProgressHUD 未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MBProgressHUD 未显示
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
