2013-07-10 25 views
-1

我有一个在加载网页时使用ATM HUD的UIWebView。我可以让HUD开始工作,但在网页加载后,它仍然在那里。我需要找到一种方法让HUD在加载后停止旋转。下面是我到目前为止的代码..无法在UIWebView for IOS项目中隐藏HUD

@implementation ThenewsViewController 

@synthesize hud; 

- (void)showHud { 
    // Show hud with activity indicator 
    NSLog(@"hud: %@", hud); 
    if (!hud) { 
     hud = [[ATMHud alloc] initWithDelegate:self]; 
     [self.navigationController.view addSubview:hud.view]; 
     [hud setCaption:@"Loading news..."]; 
     [hud setActivity:YES]; 
     [hud update]; 

     if (![hud isBeingPresented]) 
      [hud show]; 
    } else { 
     NSLog(@"hud exists... resetting."); 
     hud = nil; 
     [self showHud]; 
    } 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 

} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSURL *myURL = [NSURL URLWithString:@"http://www.hiphopdx.com/m/index.php?s=news"]; 

    NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL]; 

    [myWebView loadRequest:myRequest]; 

    UIColor *navBarColor = UIColorFromRGB(0x089932); 
    [[self.navigationController navigationBar] setTintColor:navBarColor]; 

    if (![hud isBeingPresented]) 
     [self showHud]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 

} 

- (void)viewDidFinishLoad:(UIWebView *)webView 
{ 

    NSLog(@"Done loading web view"); 
    [hud hide]; 
} 

@end 

回答

0

这个怎么样?

ATMHud *blargh; 


if(loaded) 
{ 
blargh.hidden = YES; 
} 
+0

你会把这段代码放在哪里? –

0

试试这个:

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
// stop animating here 

} 

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
{ 
// stop animating here also 

} 

另外,还要确保你的 “myWebView” 实例委托设置。 F.e _myWebView.delegate = self;

+0

除了笔记之外,还有什么应该在大括号中? –

+0

用正确的代码行(代表)更新了答案 – Injectios

+0

btw你有没有设置myWebView.delegate = self; ? – Injectios