myWebView=[[UIWebViewalloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height)];
myWebView.delegate=self;
NSURLRequest*request=[NSURLRequestrequestWithURL:[NSURLURLWithString:urlStr]];
[myWebView loadRequest:request];
[self.viewaddSubview:myWebView];
这个webview使用起来很简单。
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
NSLog(@"erros is %@",error);
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(@"hello");
}
两个代理的方法
注意一点 url字符串中如果包含了非法字符或者中文,要使用
[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
编码一下,否则会报错:Domain=WebKitErrorDomain Code=101 "The operation couldn’t be completed.