您的位置:首页 > 移动开发

UIWebView使用简介

2015-12-09 09:56 274 查看
加载网页

// 1.加载网络界面

NSURL *url = [[NSURL
alloc] initWithString:daijiawentiHTML];

[webView loadRequest:[NSURLRequest
requestWithURL:url]];

// 2.加载本地html文件

NSString *resourcePath = [ [NSBundle
mainBundle] resourcePath];

NSString *filePath = [resourcePath stringByAppendingPathComponent:@"qus2.html"];

NSString *htmlstring =[[NSString
alloc] initWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:nil];

[webView loadHTMLString:htmlstring
baseURL:[NSURL
fileURLWithPath:[[NSBundle
mainBundle]bundlePath]]];
注意本地加载时,要把引用的文件注意路径问题改成图片中


代理方法
1. 开始请求网页

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

}
2.请求网页结束
- (void)webViewDidFinishLoad:(UIWebView *)webView
{

}
3.请求网页错误
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{

}
4.每次网页请求都会调用该方法,做网页交互会用到

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

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: