1.創(chuàng)建webview
UIWebView *_myWebView = [[UIWebView allow]initWithFrame :bounds];
_myWebView.delegate=self;//代理
[self.view addSubview:_myWebView];
2.網(wǎng)絡(luò)請求數(shù)據(jù)加載到webview上
NSString * urlString=[NSString stringWithFormat:@"%@",@"http://www.baidu.com"]; //l鏈接一定加http或者https不然加載不出來
NSString *encodeStr = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; ?//轉(zhuǎn)碼防止鏈接有中文
NSURL *url = [NSURL URLWithString:encodeStr];?
[_myWebView loadRequest:request];
3.實現(xiàn)webview 代理
#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
self.title = [_myWebView stringByEvaluatingJavaScriptFromString:@"document.title"];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSString *host = request.URL.absoluteString; ?//獲取當前的URL ?根據(jù)當前的URL判斷跳轉(zhuǎn)邏輯
NSLog(@"host == %@",host);
return YES;
}
4 原生點擊事件 webview返回上個webview
[_myWebView goBack];