开发者

iPhone UiWebView images with absolute path

I display some html in my UIWebView and I have in my html references to images like: '/images/test1.gif' etc.

I display this in that way:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWi开发者_如何学JAVAthPath:path];
[myWebView loadHTMLString:someHtml baseURL:baseURL];

I've also added all required images to my Xcode project, into 'images' directory. The problem is, that, as far as I can see, the baseUrl ends with '/', and path to the images starts with '/' (it's absolute). All that makes my images doesn't appear.

I've noticed, that if I change, in html, path to images, to for example 'images/test.gif', the image will show up, but I want (if possible) to avoid changing all image paths in html from absolute to relative, becasue this html is imported from some database, and in case of another import I would have to change it again.


Have you tried clipping the slash from the end of baseURL? I should hope the web view is smart enough to add a slash where needed, despite blindly concatenating two strings that result in a double slash.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜