首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MBProgressHUD UIWebView

MBProgressHUD UIWebView
EN

Stack Overflow用户
提问于 2012-03-15 19:04:06
回答 2查看 3K关注 0票数 2

MBProgressHUD出了点小问题。我有一个网页视图,并希望在数据加载时显示HUD。HUD出现了,但只停留了几秒钟,并且已经消失了,但是webview并没有完成加载。

代码语言:javascript
复制
-(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);}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-15 19:12:30

删除showWhileExecuting方法并将hud隐藏在UIWebView的下面的委托方法中,然后它就可以正常工作了

代码语言:javascript
复制
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    [HUD hide:YES];
}
票数 5
EN

Stack Overflow用户

发布于 2012-03-15 19:11:20

我们从未将web视图与MBProgressView HUD集成在一起,而不是使用这个,您应该在这里使用UIActivityIndicator,并在webView的这个代理处停止& resignFromSuperView:

  • (void)webViewDidFinishLoad:(UIWebView *)webView

您可以在此代理中手动隐藏HUD:

代码语言:javascript
复制
 - (void)webViewDidFinishLoad:(UIWebView *)webView
{
   [HUD hide:YES];
   if(HUD!=nil)
   { 
       [HUD removeFromSuperview];
       [HUD release];
       HUD=nil;
   }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9718401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档