webViewDidFinishLoad因为网页里的重定向,会调用多次,使用web view.isLoading来解决...

我编码如下,但我发现 webViewDidFinishLoad() 会发生若干次。
如何知道 webViewDidFinishLoad() 最后发生吗?
iNavigate = 0;


- (void)webViewDidFinishLoad:(UIWebView *)webView 
{    

    iNavigate ++;


    NSLog(@"Navigate Count = %d", iNavigate);


    if (iNavigate >1)
    {
        CGRect rect = self.webView.frame;
        rect.size.height = rect.size.height - toolBarBrowser.frame.size.height;
        self.webView.frame = rect;
        self.toolBarBrowser.hidden = FALSE;
    }

    barButtonBack.enabled = (self.webView.canGoBack);
    barButtonForward.enabled = (self.webView.canGoForward);



}

 

//解决方法 1:
//您可以使用 (webview.isLoading) 来知道 UIWebView webViewDidFinishLoad 最后或发生不
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    if (!webView.isLoading){
        [self ChickUrlIsDownload:myWebview.request.URL.absoluteString];
    }
    {
        [progress setProgress:1 animated:YES];
        [progress removeFromSuperview];
        progress=nil;
    }
    if ([myWebview canGoBack]) {
        [btn_back setSelected:YES];
    }else{
        [btn_back setSelected:NO];
    }
    [btn_back setEnabled:btn_back.selected];
    if ([myWebview canGoForward]) {
        [btn_go setSelected:YES];
    }else{
        [btn_go setSelected:NO];
    }
    [btn_go setEnabled:btn_go.selected];
    //获取到title
    NSString *title=[webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    if (title.length>16) {
        sel_title=[NSString stringWithFormat:@"%@%@",[title substringWithRange:NSMakeRange(0,16)],@"..."];
    }else{
        sel_title=title;
    }
    NSLog(@"_str_title=%@",sel_title);
}

 

转载于:https://www.cnblogs.com/niit-soft-518/p/4610259.html

你可能感兴趣的:(webViewDidFinishLoad因为网页里的重定向,会调用多次,使用web view.isLoading来解决...)