无法加载URL时,UIWebView无法加载HTML字符串

时间:2014-12-12 06:30:43

标签: ios objective-c iphone html5 uiwebview

当UIWebView无法从URL加载页面时,我试图在webView didFailLoadWithError委托方法中加载“错误页面”。我试图直接加载错误页面,它的工作完美。这里我的代码如下,

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
//    [webView stopLoading];

errorMessage    = (errorMessage==nil?@"Sorry, there was an error loading the chapter":errorMessage);
refreshMessage  = (refreshMessage==nil?@"Try reloading this chapter":refreshMessage);

NSURL *imagePath = [[NSBundle mainBundle] URLForResource:@"error_icon_2x" withExtension:@"png" subdirectory:@"/www/img/"];
NSURL *cssPath = [[NSBundle mainBundle] URLForResource:@"myexp" withExtension:@"css" subdirectory:@"/www/css/"];


NSString *errorHTML = [NSString stringWithFormat:@"<head><link rel=\"stylesheet\" type=\"text/css\" href=\"%@\"><script type='text/javascript'>function callReloadPDF() { window.location  = 'ios:reloadPDF'; }</script></head><div style=\"position: relative; top: 35%%; transform: translateY(-50%%); \" class=\"errorPDFViewer\"><div style=\"\"><img src=\"%@\" width=\"30px\" height=\"30px\" class=\"newexpimgerroricon\"/></div><br /><div class=\"newexpsorrymessagelabel\">'%@'</div><div style=\"margin: 1% 30%;text-align: center; \"><button class=\"btnreloadPage\" id=\"btnreloadPage' + index + '\" onclick='callReloadPDF()'>'%@'</button></div></div>", cssPath, imagePath, errorMessage, refreshMessage];

NSLog(@"errorHTML: %@", errorHTML);

[webView loadHTMLString:errorHTML baseURL:nil];

}

任何帮助将不胜感激:)谢谢!!!

0 个答案:

没有答案