UIWebView 之 遇到小问题

1.页面没有加载完走了失败的代理方法(uiwebview didFailLoadWithError -999 error code):

在uiwebview里,如果load一个url还没结束就立即load另一个url,那么就会callback didFailLoadWithError method,error code is -999。solution is 在didFailLoadWithError 里添加下列code

<p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light';"><span style="font-size:14px;"><span style="color: rgb(255, 255, 255);"><strong> </strong></span><strong>if ([error code] != NSURLErrorCancelled) {</strong></span></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light'; min-height: 13px;"><strong><span style="font-size:14px;">        </span></strong></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light';"><span style="font-size:14px;"><strong>        self.failLoadingView = [[SGDefaultView alloc] initWithFrame:self.view.bounds AndY:100 DefaultView:@"no_network_img" AndText:@"Ooops!网络不好..." AndButton:@"刷新"AndBlock:nil];</strong></span></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light';"><span style="font-size:14px;"><strong>        [self.view addSubview:_failLoadingView];</strong></span></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light'; min-height: 13px;"><strong><span style="font-size:14px;">        </span></strong></p><p style="margin-top: 0px; margin-bottom: 0px; line-height: normal; font-family: 'Heiti SC Light';"><strong><span style="font-size:14px;">    }</span></strong></p>
2.获取网页的标题:

NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"]; 

3.webview返回效果处理:

//用苹果自带的返回键按钮处理如下(自定义的返回按钮)

- (void)returnBack:(UIBarButtonItem *)btn

{

    if ([self.baseWebView canGoBack]) {

        [self.baseWebView goBack];

        

    }else{

        [self.view resignFirstResponder];

        [self.navigationController popViewControllerAnimated:YES];

    }

}


#pragma mark - UIWebViewDelegate

-(void)webViewDidFinishLoad:(UIWebView *)webView

{

    self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];;

}

//如果是H5页面里面自带的返回按钮处理如下:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    NSString * requestString = [[request URL] absoluteString];

    requestString = [requestString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    //获取H5页面里面按钮的操作方法,根据这个进行判断返回是内部的还是push的上一级页面

    if ([requestString hasPrefix:@"goback:"]) {

        [self.navigationController popViewControllerAnimated:YES];

    }else{

        [self.baseWebView goBack];

    }

    return YES;

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值