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

2023-11-09移动开发问题
4

本文介绍了从 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 文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

游戏中心 facebook 喜欢
Game center facebook like(游戏中心 facebook 喜欢)...
2024-08-12 移动开发问题
3

从 Documents 目录存储和读取文件 iOS 5
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)...
2024-08-12 移动开发问题
9