IOS webView 因URL中含有中文加载网页白屏显示的解决方法

来源:互联网 发布:诺基亚n97的软件 编辑:程序博客网 时间:2024/06/10 05:45

近日工程中有用到webview加载网页,有两个入口可以进入到含有webview的controller, 打开webView的URL中含有中文字段,加载后webView显示白屏,后来发现iOS webView加载的URL中不可以有中文符号,解决办法就是将中文符号UTF8转码,代码如下:

    UIWebView *webview = [[UIWebViewalloc]init];

    webview.frame =CGRectMake(0,0, screenWidth,screenHeight);

    webview.delegate=self;

    [self.viewaddSubview:webview];    

    NSString *urlString =[[NSStringstringWithFormat:@"http://api.map.baidu.com/marker?location=%@,%@&title=%@&content=%@&output=html",_latitude,_longitude,@"标题",@"地址"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSURL *url = [NSURLURLWithString:urlString];

    [webview loadRequest:[NSURLRequestrequestWithURL:url]];



1 0
原创粉丝点击