Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
Objective c 从XCode调用本地HTML文件时出现问题_Objective C_File_Uiwebview_Local - Fatal编程技术网

Objective c 从XCode调用本地HTML文件时出现问题

Objective c 从XCode调用本地HTML文件时出现问题,objective-c,file,uiwebview,local,Objective C,File,Uiwebview,Local,以下是我的WebView代码: [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]]; 这是我的错误: *** Terminating app due to uncaught exception 'NSInvalidArgumentExcep

以下是我的WebView代码:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];
这是我的错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '*** -[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'
有人能帮忙吗?它表示nil字符串,但NSURL字符串是index.html


我唯一的想法是,索引文件可能没有正确存储。它位于项目目录中-与XCode项目文件xcodeproj和info.plist的文件夹相同,URL必须定义如何获取信息,而不仅仅是文件的名称。这意味着您必须指定完整的URL,如或file:///Users/Daniel/Sites/index.html. 您指定的是URI而不是URL

有关URL和URI之间的差异:


用于NSURL的Apple文档:

检查文件是否已复制到应用程序包中。当
[[NSBundle mainBundle]pathForResource:ofType::
返回nil时,包中很可能没有具有此名称的文件


在Xcode3中,右键单击侧栏中的“组和文件”标题并选择“目标成员资格”。确保选中index.html前面的复选框。

fileURLWithPath:
isDirectory:
之间没有空格,这没有区别。我从教程中复制/粘贴了上面的代码。并且
fileURLWithPath:isDirectory:
从路径中创建了一个URL。很好,我没有意识到这一点。谢谢+1未经检查。谢谢你,伙计。如果我在web/index.html中有该文件,我该怎么做?它不接受
pathForResource:@“web/index”的类型:@“html”]