为什么我的HTML文件找不到我的CSS和Javascript文件在UIWebView中呈现?

时间:2011-09-29 15:55:25

标签: javascript objective-c css ipad uiwebview

以下是成功将HTML加载到UIWebView中的代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Player" ofType:@"html"];  
    NSData *htmlData = [NSData dataWithContentsOfFile:filePath];  
    if (htmlData) {  
        NSBundle *bundle = [NSBundle mainBundle]; 
        NSString *path = [bundle bundlePath];
        NSString *fullPath = [NSBundle pathForResource:@"Player" ofType:@"html" inDirectory:path];
        [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:fullPath]]];
    }
}

这是Player.html的顶部,HTML文件正在加载和显示,只有零样式或javascript操作:

<head><title>
    Course: Pegasus 1 of each
</title><link href="Content/css/jqueryui.css" type="text/css" media="screen" rel="Stylesheet" /><link href="Content/css/Templates.css" type="text/css" media="screen" rel="Stylesheet" /><link href="Scripts/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" rel="Stylesheet" /><link href="Content/css/Pegasus.css" type="text/css" media="screen" rel="Stylesheet" />

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript"></script>
    <script src="https://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js" type="text/javascript"></script>

    <script src="Scripts/browser.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8" src="Scripts/jstree/jquery.tree.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script>

    <script type="text/javascript" src="Scripts/fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
    <script type="text/javascript" src="Scripts/fancybox/jquery.easing-1.3.pack.js"></script>
    <script type="text/javascript" src="Scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <script type="text/javascript" src="Scripts/jquery.carouFredSel-2.5.5-packed.js"></script>
    <script type="text/javascript" src="Scripts/jquery.qtip-1.0.min.js"></script>
    <script type="text/javascript" src="Scripts/jquery.multifilterie.js"></script>
    <script type="text/javascript" src="Scripts/pegasus.js"></script>
    <script type="text/javascript" src="Scripts/jwplayer/jwplayer.js"></script>
    <script src="Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="Scripts/raphael-min.js" type="text/javascript"></script>
    <script type="text/javascript" src="Scripts/pegasus.quiz.js"></script>

这是Group结构,请注意路径相对于Player.html的根位置:

enter image description here

但这就是我所得到的:

enter image description here

我该怎么做才能找到文件?

1 个答案:

答案 0 :(得分:2)

您在Xcode中看到的组结构不是文件夹结构。这是组织项目工作区的一种方式 在复制包资源构建阶段,文件将复制到应用程序包的根目录。

~/Library/Apllication Support/IPhone Simulator/4.x.x/Applications/uid here/your.app中检查您的资源目录。您将看到没有Scripts文件夹。

这样的东西
<script src="./browser.js" type="text/javascript"></script>

应该有用。


如果您确实需要在应用包中添加文件夹结构,请在添加ScriptsContent文件夹时选择“为任何添加的文件夹创建文件夹引用”到您的项目资源。