【发布时间】:2014-04-05 09:10:09
【问题描述】:
我想从我的应用程序文档目录中获取图像到标签中的 UIwebview。
Document 目录位于应用程序根目录中:
/Users/myname/Library/Application Support/iPhone Simulator/7.1-64/Applications/E6B53F7B-CCC0-43A0-B1EB-D7C60E10E6CB/
图像位于:
/Users/myname/Library/Application Support/iPhone Simulator/7.1-64/Applications/E6B53F7B-CCC0-43A0-B1EB-D7C60E10E6CB/Documents/image.jpg
我的 uiwebview 代码是:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@", documentsDirectory];
NSURL *url = [NSURL URLWithString:filePath];
[webView loadHTMLString:HTMLMarkup baseURL:url];
src 属性设置为只是图像名称,但这似乎不起作用。我确定它与获取图像的相对路径有关,但我不知道 uiwebview 上加载的页面的根位于何处。
我认为上面的代码将 uiwebview 的根路径设置为 Documents 目录,因此我可以简单地通过其名称调用图像。
有谁知道这里的问题是什么?
【问题讨论】:
标签: ios iphone objective-c uiwebview