开发者

Why are my CSS and Javascript files not being found by my HTML file rendered in UIWebView?

Here is the code that is successfully loading the HTML into 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]]];
    }
}

Here is the top part of Player.html, the HTML file is being loaded and shown, just with zero styling or javascript action:

<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/b开发者_StackOverflow中文版eta1/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>

Here is the Group structure, notice that the paths are relative to the root location of Player.html:

Why are my CSS and Javascript files not being found by my HTML file rendered in UIWebView?

But this is what I am getting:

Why are my CSS and Javascript files not being found by my HTML file rendered in UIWebView?

What should I do to make it find the files?


The group structure you see in Xcode is not a folder structure. It's a way to organize your project workspace.
During the Copy Bundle Resources build phase, the files are copied to the root of your app bundle.

Check your resource dir in ~/Library/Apllication Support/IPhone Simulator/4.x.x/Applications/uid here/your.app. You will see that there is no Scripts folder.

Something like

<script src="./browser.js" type="text/javascript"></script>

should work.


If you really need to have a folder structure in your app bundle, select "Create Folder References for any added folders" when you add the Scripts and Content folders to your project resources.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜