我尝试将 URL(字符串格式)加载到 UIWebView,但它没有显示网页,而是显示了 URL。这是我的代码:
URL = @"www.Google.com"
NSString *path = [[NSBundle mainBundle] bundlePath];
baseURL = [NSURL fileURLWithPath:path];
[webView clearsContextBeforeDrawing];
[webView loadHTMLString:URL baseURL:baseURL];
[webView setNeedsLayout];
最佳答案
loadHTMLString:baseURL:
将 html 页面内容作为输入,而不仅仅是字符串形式的 URL。它将 www.Google.com
视为 html 字符串并显示出来。你将不得不做,
NSString * htmlString = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com"] encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];
关于ios - UIWebView 显示 URL 而不是网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6354832/