我有一个webview和一个activityIndicator,我希望当URL加载时,activityIndicator会停止。我有这个:
XYZViewController.h
@interface XYZViewController : UIViewController <UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *browser;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@end
XYZViewController.m
-(void)viewDidLoad {
[super viewDidLoad];
self.activityIndicator.hidden = NO;
[self.activityIndicator startAnimating];
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com"]];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[self.browser loadRequest:request];
}
-(void) webViewDidFinishLoad:(UIWebView *)webView {
[self.activityIndicator stopAnimating];
self.activityIndicator.hidden = YES;
}
AppDelegate.m
XYZViewController* viewVC = [XYZViewController alloc]init];
viewVC.browser.delegate = viewVC;
我不知道这是错的?
有人帮帮我吗?
答案 0 :(得分:0)
执行@puzzl建议的内容,然后将其添加到webViewDidStartLoad:
而不是viewDidLoad
- (void)viewDidLoad {
...
self.browser.delegate = self
...
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
self.activityIndicator.hidden = NO;
[self.activityIndicator startAnimating];
}