【发布时间】:2011-10-23 09:41:29
【问题描述】:
我正在学习编写一个 iOS 原生 webkit 应用程序。在 Xcode 3.x 中,我将 index.html 分布在 Resources 文件夹中,并且以下代码可以正常工作:
- (void)viewDidUnload
{
[super viewDidUnload];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
if (htmlData)
{
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle bundlePath];
NSString *fullPath = [NSBundle pathForResource:@"index" ofType:@"html" inDirectory:path];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:fullPath]]];
}
}
我在 Xcode 4.2 上创建项目时未加载 index.html。我在“支持文件”文件夹中有 index.html。我错过了什么吗?请帮忙。
谢谢
阿德里安
【问题讨论】:
-
抱歉这个问题。该函数应该是 viewDidLoad,而不是 viewDidUnload。
-
您可以将其发布为答案并将其标记为正确以关闭问题
-
对不起。这是我在这里的第一篇文章,但我正在学习。感谢您的耐心等待。
-
这不是问题。我发表评论的目的是帮助您学习。我也赞成你的答案,因为它是正确的。