MBProgressHUD没有显示 [英] MBProgressHUD not showing

查看:329
本文介绍了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没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆