MBProgressHUD出了点问题。我有一个webview,想要在加载数据时显示HUD。 HUD出现但只停留了几秒钟并且已经消失但是webview没有完成加载。
-(void)viewDidAppear:(BOOL)animated{
// 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];
// Regisete for HUD callbacks so we can remove it from the window at the right time
HUD.delegate = self;
HUD.labelText = @"Loading";
HUD.detailsLabelText = @"updating data";
// Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:@selector(loadingWebView) onTarget:self withObject:nil animated:YES];}
- (void) loadingWebView {
NSString *fullURL = beverageViewString;
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[beverageView loadRequest:requestObj];
NSLog(@"%@",beverageViewString);}
答案 0 :(得分:5)
删除showWhileExecuting方法并在UIWebView的以下委托方法中隐藏hud然后它将正常工作
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[HUD hide:YES];
}
答案 1 :(得分:1)
我们从未将Web视图与MBProgressView HUD集成,而不是使用它,您应该在此处使用UIActivityIndicator并停止&这个webView委托的resignFromSuperView:
- (void)webViewDidFinishLoad:(UIWebView *)webView
你可以在这个代表处手动隐藏HUD:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[HUD hide:YES];
if(HUD!=nil)
{
[HUD removeFromSuperview];
[HUD release];
HUD=nil;
}
}