gpt4 book ai didi

objective-c - pathForResource inDirectory 问题

转载 作者:行者123 更新时间:2023-12-03 16:49:29 24 4
gpt4 key购买 nike

我想从 WebView 中的资源加载 html 文件。

在我拥有的资源中:

测试.html

测试文件夹->test.html

此代码完美运行:

[[webview1 mainFrame] loadRequest:
[NSURLRequest requestWithURL:
[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"]]]];

还有这个 - 使应用程序崩溃 (SIGABRT):

[[webview1 mainFrame] loadRequest:
[NSURLRequest requestWithURL:
[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html" inDirectory:@"testfolder" ]]]];

如何从文件夹中获取文件?

最佳答案

您的处理方式是正确的,因此这意味着您的文件/目录名称中存在拼写错误,或者“testfolder”目录未包含在您的应用程序包中。

确保“testfolder”作为文件夹(而不是组)位于 XCode 项目的资源部分中。

构建应用程序时查看“构建结果”窗口;您应该会看到其中显示“复制 test.html”和“复制 testfolder”的步骤。

请注意(在构建模拟器时)您还可以直接检查应用程序包的内容 - 查看 Library/Application Support/iPhone Simulator/User/Applications

关于objective-c - pathForResource inDirectory 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2327505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com