gpt4 book ai didi

iphone - MBProgressHUD 未显示

转载 作者:行者123 更新时间:2023-12-01 17:13:58 30 4
gpt4 key购买 nike

在我的应用程序中,我正在加载一个资源繁重的 View ,加载大约需要 1 到 2 秒。所以我将它加载到一个单独的线程中,如下所示:

hud = [[MBProgressHUD alloc] init];
[hud showWhileExecuting:@selector(loadWorkbench:) onTarget:self withObject:nil animated:YES];

但是它从未出现,并且应用程序在最终用户看来是卡住的。有什么想法我哪里出错了吗?

最佳答案

是的。它不会出现,因为您从未告诉将 HUD 添加为窗口的 subview 。尝试类似:

    // 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 委托(delegate),因此还要添加以下委托(delegate)方法:
- (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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com