【问题标题】:Why is path not working in Xcode 4.2?为什么路径在 Xcode 4.2 中不起作用?
【发布时间】: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。
  • 您可以将其发布为答案并将其标记为正确以关闭问题
  • 对不起。这是我在这里的第一篇文章,但我正在学习。感谢您的耐心等待。
  • 这不是问题。我发表评论的目的是帮助您学习。我也赞成你的答案,因为它是正确的。

标签: ios xcode webkit native


【解决方案1】:

这是我的粗心。函数应该是 viewDidLoad,而不是 viewDidUnload。

谢谢。

【讨论】:

    猜你喜欢
    • 2016-05-22
    • 2014-10-08
    • 2013-03-21
    • 2013-10-20
    • 1970-01-01
    • 2010-10-05
    • 2016-11-08
    • 2012-03-10
    • 1970-01-01
    相关资源
    最近更新 更多