为什么路径在 Xcode 4.2 中不起作用?
我正在学习编写 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。我错过了什么吗?请帮忙。
谢谢
阿德里安
I am learning to write an iOS-native webkit app. In Xcode 3.x, I have index.html distributed in Resources folder and the following code works correctly:
- (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]]];
}
}
The index.html is not loaded when I create a project on Xcode 4.2. I have the index.html in the "Supporting Files" folder. Have I missed something? Please help.
Thanks
Adrian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的粗心。该函数应该是viewDidLoad,而不是viewDidUnload。
谢谢。
It was my carelessness. The function should be viewDidLoad, not viewDidUnload.
Thanks.