本文简述webView加载一个网页,代码如下:
//遵循代理
<UIWebViewDelegate>
//设置代理
_webView.delegate = self;
#pragma mark 开始加载数据
- (void)startLoad
{
NSURL* url = [NSURL URLWithString:urlStr];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}
#pragma mark webViewDelegate
// 开始加载
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
}
// 结束加载
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
// 开始加载失败
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
网友评论