UIWebView: webViewDidStartLoad/webViewDidFinishLoad delegate methods not called when loading certain URLs

前端 未结 3 1336
日久生厌
日久生厌 2021-02-04 05:06

I have basic web browser implemented using a UIWebView. I\'ve noticed that for some pages, none of the UIWebViewDelegate methods are called.

An

3条回答
  •  庸人自扰
    2021-02-04 05:44

    this is not good solution but im using NSTimer for updating status of buttons:

    - (BOOL)webView:(UIWebView *)_webview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
        if (!_timer && [request.URL.absoluteString rangeOfString:@"youtube.com"].length != 0) {
            _timer = [NSTimer scheduledTimerWithTimeInterval:0.5
                                                      target:self
                                                    selector:@selector(checkNavigationStatus)
                                                    userInfo:nil
                                                     repeats:YES];
        }
    
        return YES;
    }
    
    //....
    //....
    //....
    
    - (void)checkNavigationStatus
    {
        // Check if we can go forward or back
        backButton.enabled = self.webView.canGoBack;
        forwardButton.enabled = self.webView.canGoForward;
    }
    

提交回复
热议问题