Commit 9530e7509155ad1ff7709823fe69c9e61ba09145
1 parent
94b1f759
no message
Showing
1 changed file
with
43 additions
and
4 deletions
CNLiveScioLive/Pages/Home/新闻详情/OldController/OldArticleDetailViewController.m
| @@ -20,7 +20,10 @@ | @@ -20,7 +20,10 @@ | ||
| 20 | NSString *htmlString; | 20 | NSString *htmlString; |
| 21 | NSString *htmlUrl; | 21 | NSString *htmlUrl; |
| 22 | BOOL isHaveVideo; | 22 | BOOL isHaveVideo; |
| 23 | + NSInteger isFail; | ||
| 23 | } | 24 | } |
| 25 | +@property (nonatomic, strong) UIButton *refresh; | ||
| 26 | + | ||
| 24 | @end | 27 | @end |
| 25 | @implementation OldArticleDetailViewController | 28 | @implementation OldArticleDetailViewController |
| 26 | - (id)initWithDictionary:(NSDictionary*)dictionary{ | 29 | - (id)initWithDictionary:(NSDictionary*)dictionary{ |
| @@ -85,11 +88,19 @@ | @@ -85,11 +88,19 @@ | ||
| 85 | // NSLog(@"%@",dic); | 88 | // NSLog(@"%@",dic); |
| 86 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { | 89 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { |
| 87 | [_webView loadHTMLString:[self setHTMLString:dic[@"content"]] baseURL:nil]; | 90 | [_webView loadHTMLString:[self setHTMLString:dic[@"content"]] baseURL:nil]; |
| 91 | + isFail = 0; | ||
| 92 | + _refresh.hidden = YES; | ||
| 88 | 93 | ||
| 89 | } else { | 94 | } else { |
| 95 | + isFail++; | ||
| 90 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; | 96 | [AlertViewTool showHUDViewText:dic[@"errorMessage"]]; |
| 91 | - | 97 | + if (isFail == 1) { |
| 98 | + [self getDetailsData]; | ||
| 99 | + } else if (isFail > 1) { | ||
| 100 | + _refresh.hidden = NO; | ||
| 101 | + } | ||
| 92 | } | 102 | } |
| 103 | + | ||
| 93 | } | 104 | } |
| 94 | failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { | 105 | failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { |
| 95 | // 请求失败 | 106 | // 请求失败 |
| @@ -269,7 +280,6 @@ | @@ -269,7 +280,6 @@ | ||
| 269 | } | 280 | } |
| 270 | 281 | ||
| 271 | self.scrollView.backgroundColor = [UIColor whiteColor]; | 282 | self.scrollView.backgroundColor = [UIColor whiteColor]; |
| 272 | - | ||
| 273 | [self.view addSubview:self.scrollView]; | 283 | [self.view addSubview:self.scrollView]; |
| 274 | 284 | ||
| 275 | NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"; | 285 | NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);"; |
| @@ -324,8 +334,30 @@ | @@ -324,8 +334,30 @@ | ||
| 324 | hasLoad = NO; | 334 | hasLoad = NO; |
| 325 | // [self loadData]; | 335 | // [self loadData]; |
| 326 | [self getDetailsData]; | 336 | [self getDetailsData]; |
| 337 | + | ||
| 338 | + [self.view addSubview:self.refresh]; | ||
| 339 | +} | ||
| 340 | +- (void)refreshDidClicked:(UIButton *)btn { | ||
| 341 | + [self getDetailsData]; | ||
| 342 | +} | ||
| 343 | +- (UIButton *)refresh { | ||
| 344 | + if (!_refresh) { | ||
| 345 | + _refresh = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
| 346 | + _refresh.frame = CGRectMake(0, 0, 100, 40); | ||
| 347 | + _refresh.layer.masksToBounds = YES; | ||
| 348 | + _refresh.layer.cornerRadius = 5; | ||
| 349 | + _refresh.center = self.view.center; | ||
| 350 | + _refresh.backgroundColor = Color_Blue; | ||
| 351 | + [_refresh setTitle:@"重试" forState:UIControlStateNormal]; | ||
| 352 | + [_refresh setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | ||
| 353 | + [_refresh setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected]; | ||
| 354 | + _refresh.titleLabel.font = [UIFont systemFontOfSize:13]; | ||
| 355 | + [_refresh addTarget:self action:@selector(refreshDidClicked:) forControlEvents:UIControlEventTouchUpInside]; | ||
| 356 | + _refresh.adjustsImageWhenHighlighted = NO; | ||
| 357 | + _refresh.hidden = YES; | ||
| 358 | + } | ||
| 359 | + return _refresh; | ||
| 327 | } | 360 | } |
| 328 | - | ||
| 329 | - (void)viewWillAppear:(BOOL)animated { | 361 | - (void)viewWillAppear:(BOOL)animated { |
| 330 | [super viewWillAppear:animated]; | 362 | [super viewWillAppear:animated]; |
| 331 | 363 | ||
| @@ -411,8 +443,15 @@ | @@ -411,8 +443,15 @@ | ||
| 411 | } | 443 | } |
| 412 | decisionHandler(WKNavigationActionPolicyAllow); | 444 | decisionHandler(WKNavigationActionPolicyAllow); |
| 413 | } | 445 | } |
| 414 | - | 446 | +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(null_unspecified WKNavigation *)navigation { |
| 447 | + [AlertViewTool showHUDView]; | ||
| 448 | +} | ||
| 449 | +- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error { | ||
| 450 | + [AlertViewTool hideHUDView]; | ||
| 451 | +} | ||
| 452 | + | ||
| 415 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation { | 453 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation { |
| 454 | + [AlertViewTool hideHUDView]; | ||
| 416 | _imageArray = [_webView getImgs]; | 455 | _imageArray = [_webView getImgs]; |
| 417 | NSMutableArray *array = [NSMutableArray array]; | 456 | NSMutableArray *array = [NSMutableArray array]; |
| 418 | for (NSString *string in _imageArray) { | 457 | for (NSString *string in _imageArray) { |