loadHTMLString 不适用于 iOS5?
以下代码不适用于 iOS5:
- (void)loadURL
{
NSString *path = [[NSBundle mainBundle] pathForResource:self.HTML ofType:@"html"];
NSString *markup = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:markup baseURL:nil];
[markup release];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
// Another controller loads
return NO;
}
else
{
return YES;
}
}
加载 Web 视图时,它不执行任何操作,只出现一个空屏幕。当我在 iOS 4.3 中运行它时,它会从包中加载 HTML。
The following code does not work with iOS5:
- (void)loadURL
{
NSString *path = [[NSBundle mainBundle] pathForResource:self.HTML ofType:@"html"];
NSString *markup = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:markup baseURL:nil];
[markup release];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if (navigationType == UIWebViewNavigationTypeLinkClicked)
{
// Another controller loads
return NO;
}
else
{
return YES;
}
}
When the web view loads, it does nothing, just an empty screen appears. When I run this in iOS 4.3 it loads the HTML from the bundle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的 html 包含自关闭的脚本标记
标记,那么这可能是问题的原因。
请参阅我自己的问题及其解决方案,此处:UIWebView loadHTMLString not work in iOS5
If your html includes a script tag that is self-closing
<script src="..." />
tag then this is likely the cause of the problem.See my own question with solution, here: UIWebView loadHTMLString not working in iOS5