0

我正在尝试在我的应用程序中运行以下代码(参考:iPhone Dev: UIWebView baseUrl to resources in Documents folder not App bundle

NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

NSString *HTMLData = @"<h1>Hello this is a test</h1><img src="sample.jpg" alt="" width="100" height="100" />";
[webView loadHTMLString:HTMLData baseURL:
[NSURL URLWithString: 
[NSString stringWithFormat:@"file:/%@//",imagePath]
]];

它在单独的项目中运行良好。但是当我在我现有的项目中尝试它时,我在控制台上得到以下内容,然后是空白 webView :

 *** WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: <NSRangeException> *** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]

关于我应该在哪里寻找的任何想法。在我的代码中?

4

2 回答 2

1

做这个:

 NSString *path = [[NSBundle mainBundle] bundlePath];
 NSURL *baseURL = [NSURL fileURLWithPath:path];
 NSString *strHTML = @"<html><h1>Hello this is a test</h1><img src="sample.jpg" alt="" width="100" height="100" /></html>";
 [webView loadHTMLString:strHTML baseURL:baseURL];
于 2012-09-05T06:02:40.500 回答
-4

很抱歉……出现了问题- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType

我的错,被奇怪的 webkit 消息冲昏了头脑

于 2012-09-05T05:46:05.193 回答