近日工程中有用到webview加载网页,有两个入口可以进入到含有webview的controller, 打开webView的URL中含有中文字段,加载后webView显示白屏,后来发现iOS webView加载的URL中不可以有中文符号,解决办法就是将中文符号UTF8转码,代码如下:
UIWebView *webview = [[UIWebView alloc]init];
webview.frame = CGRectMake(0, 0, screenWidth,screenHeight);
webview.delegate=self;
[self.view addSubview:webview];
NSString *urlString =[[NSString stringWithFormat:@"http://api.map.baidu.com/marker?location=%@,%@&title=%@&content=%@&output=html",_latitude,_longitude,@"标题",@"地址"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];
[webview loadRequest:[NSURLRequest requestWithURL:url]];