Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从文档目录获取图像以在UIWebView上查看_Ios_Iphone_Objective C_Uiwebview - Fatal编程技术网

Ios 从文档目录获取图像以在UIWebView上查看

Ios 从文档目录获取图像以在UIWebView上查看,ios,iphone,objective-c,uiwebview,Ios,Iphone,Objective C,Uiwebview,我想将图像从我的apps Documents目录获取到UIwebview in标记中 文档目录位于应用程序根目录中: /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/A

我想将图像从我的apps Documents目录获取到UIwebview in标记中

文档目录位于应用程序根目录中:

/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目录,这样我就可以简单地通过图像的名称来调用图像


有人知道这里有什么问题吗

令人困惑的是,
+URLWithString:
方法对本地文件不起作用。您需要
+fileURLWithPath:
。这件事让我有好几次措手不及。文件