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 | 20 | NSString *htmlString; |
| 21 | 21 | NSString *htmlUrl; |
| 22 | 22 | BOOL isHaveVideo; |
| 23 | + NSInteger isFail; | |
| 23 | 24 | } |
| 25 | +@property (nonatomic, strong) UIButton *refresh; | |
| 26 | + | |
| 24 | 27 | @end |
| 25 | 28 | @implementation OldArticleDetailViewController |
| 26 | 29 | - (id)initWithDictionary:(NSDictionary*)dictionary{ |
| ... | ... | @@ -85,11 +88,19 @@ |
| 85 | 88 | // NSLog(@"%@",dic); |
| 86 | 89 | if ([dic[@"errorCode"] isEqualToString:@"0"]) { |
| 87 | 90 | [_webView loadHTMLString:[self setHTMLString:dic[@"content"]] baseURL:nil]; |
| 91 | + isFail = 0; | |
| 92 | + _refresh.hidden = YES; | |
| 88 | 93 | |
| 89 | 94 | } else { |
| 95 | + isFail++; | |
| 90 | 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 | 105 | failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { |
| 95 | 106 | // 请求失败 |
| ... | ... | @@ -269,7 +280,6 @@ |
| 269 | 280 | } |
| 270 | 281 | |
| 271 | 282 | self.scrollView.backgroundColor = [UIColor whiteColor]; |
| 272 | - | |
| 273 | 283 | [self.view addSubview:self.scrollView]; |
| 274 | 284 | |
| 275 | 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 | 334 | hasLoad = NO; |
| 325 | 335 | // [self loadData]; |
| 326 | 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 | 361 | - (void)viewWillAppear:(BOOL)animated { |
| 330 | 362 | [super viewWillAppear:animated]; |
| 331 | 363 | |
| ... | ... | @@ -411,8 +443,15 @@ |
| 411 | 443 | } |
| 412 | 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 | 453 | - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation*)navigation { |
| 454 | + [AlertViewTool hideHUDView]; | |
| 416 | 455 | _imageArray = [_webView getImgs]; |
| 417 | 456 | NSMutableArray *array = [NSMutableArray array]; |
| 418 | 457 | for (NSString *string in _imageArray) { | ... | ... |