Use UIRefreshControl for UIWebView

前端 未结 8 927
花落未央
花落未央 2021-02-01 08:24

I saw the UIRefreshControl in iOS 6 and my question is if it is possible to refresh a WebView by pulling it down and than let it pop up like in mail? Code I used rabih is the We

8条回答
  •  情书的邮戳
    2021-02-01 09:07

    Extending @umut-can-köseali answer to have better control of the UIRefreshControl when refresh ends:

    - (void)viewDidLoad {
        [super viewDidLoad];
        _refreshControl = [[UIRefreshControl alloc] init];
        [_refreshControl addTarget:self action:@selector(handleWebViewRefresh:) forControlEvents:UIControlEventValueChanged];
        [self.webView.scrollView addSubview:_refreshControl]; //<- this is point to use. Add "scrollView" property.
    }
    
    - (void)webView:(UIWebView *)_webView didFailLoadWithError:(NSError *)error {
        [_refreshControl endRefreshing];
    }
    
    - (void)webViewDidFinishLoad:(UIWebView *)_webView {
        NSString *navigatorUrl = _webView.request.URL.absoluteString;
        if( navigatorUrl && ![navigatorUrl isEqualToString:@""]) {
            NSString *host=_webView.request.URL.host;
            NSString *path=_webView.request.URL.path;
            [_refreshControl endRefreshing];
        }
    }
    

提交回复
热议问题