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 に答える