【发布时间】:2016-02-07 10:26:33
【问题描述】:
您好,我想从我的项目中加载 html 和 .js 文件。这些是我通过框架加载 html 文件的以下步骤,但我无法点击 html 文件。
接下来的步骤。
创建了一个框架,其中包含 webview 作为子视图。
创建 Resource.bundle 并将我所有的 html、.js 文件和图像添加到包中。
当我将此框架添加到我的项目中并尝试从包中访问图像时,我无法访问。 当我尝试点击 html 文件时,我无法在我的 webview 中加载 html 文件。
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Resource" ofType:@"bundle"];
NSString *htmlFile = [[NSBundle bundleWithPath:bundlePath] pathForResource:@"simple" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
NSURL *url=[[NSBundle mainBundle] bundleURL];
[webview loadHTMLString:htmlString baseURL:url];
[self addSubview:webview];
谁能告诉我为什么这行不通,这是正确的做法吗?
【问题讨论】:
-
试试这个 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"] isDirectory:NO]]];
-
您确认资源确实在捆绑包中吗?检查您的构建产品并使用 Finder 打开捆绑包。
-
@Joris Kluivers 是的资源在捆绑包中......
标签: html ios objective-c iphone xcode