开发者

How to access files within my bundle?

I have a simple question, but don't seem to see the answer in a pr开发者_C百科evious thread, so here goes.

I want to access image files within my bundle, and the paste this string into html in various UIWebViews.

The code below seems to return a garbage string. It does not return nil, so I assume my found.

NSString *imageString = [[NSBundle mainBundle] pathForResource:@"myimage" ofType:@"png"];

Am I accessing this file correctly?


If you are inserting the string into your HTML, remember it should be a URL and not a path to a file. You may be able to simply add "file://" to the front, or you could use a NSURL object as follows:

NSString* urlString = [[NSURL fileURLWithPath:imageString] absolutePath];

Then inject urlString into your HTML instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜