- (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[UIWebView alloc ] initWithFrame:CGRectMake(0, 0, kScreenWidth+80, kScreenHeight-64)];
self.webView.backgroundColor = [UIColor whiteColor];
self.webView.scrollView.bounces = YES;
self.webView.scrollView.delegate = self;
self.webView.delegate = self;
[self loadingDataForWebView];
[self.view addSubview:self.webView];
}
#pragma mark - webView delegate
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[MBProgressHUD hideHUDForView:self.view animated:NO];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[MBProgressHUD hideHUDForView:self.view animated:NO];
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(loadingDataForWebView)];
//在label上面添加手勢
[self.label addGestureRecognizer:tap];
[self.view addSubview:self.label];
}
#pragma mark - tap
- (void)loadingDataForWebView {
[self.label removeFromSuperview];
NSString * urlString = [NSString stringWithFormat:@"%@index.php/home/Api/faultdetail.html?id=%@", XRZUrlString, self.aid];
NSLog(@"aid 是什么鬼啊 |%@",urlString);
NSURL * url = [NSURL URLWithString:urlString];
//需要將網(wǎng)址進行轉(zhuǎn)碼,否則返回的數(shù)據(jù)為亂碼
NSString * strUrl = [[NSString alloc]initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:strUrl baseURL:url];
//? ? [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:strUrl]]];
}
#pragma mark - lazy loading
- (UILabel *)label
{
if (_label == nil)
{
_label = [[UILabel alloc] initWithFrame:CGRectMake(80, 0, kScreenWidth, 200)];
_label.text = @"網(wǎng)絡不給力嫉戚,點擊重新加載";
_label.textColor = XRZredColor;
_label.userInteractionEnabled = YES;
}
return _label;
}
@end