问题描述
这是我的 WebView 代码:
Here's my WebView Code:
[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
Can anyone help? It's saying nil string but the NSURL string is index.html
我唯一的想法是索引文件可能没有正确存储.它在项目目录中 - 与 XCode 项目文件 xcodeproj 和 info.plist 相同的文件夹
My only thought is that perhaps the index file isn't stored correctly. It's in the project directory - the same folder as the XCode project file xcodeproj and the info.plist
推荐答案
检查文件是否已复制到您的应用程序包中.当 [[NSBundle mainBundle] pathForResource:ofType:]
返回 nil 时,很可能包中没有同名的文件
Check that the file is copied to your application bundle. When [[NSBundle mainBundle] pathForResource:ofType:]
returns nil very most likely there is no file with this name in the bundle
在 Xcode3 中,右键单击侧栏中的组和文件"标题并选择目标成员资格".确保 index.html 前面的复选框被选中.
In Xcode3 right click the "Groups & Files" header in the side bar and select "target membership". Make sure the checkbox in front of index.html is checked.
这篇关于从 XCode 调用本地 HTML 文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!