Problem calling a Local HTML File from XCode(从 XCode 调用本地 HTML 文件时出现问题)
问题描述
这是我的 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 文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 XCode 调用本地 HTML 文件时出现问题
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
