问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/7788349/loadhtmlstring-not-working-with-ios5