0

I am trying to include a folder structure into my xcode project that contains html, css, js and images like below:

htmlcontent
    html
       test.html
    css
       test.css
    js
       test.js

I copied the folder and its subfolder to xcode and i can see the heirachy there but when i do the following:

NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:pathToFile isDirectory:NO];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];

it prints:

/Users/scoota/Library/Application Support/iPhone Simulator/6.0/Applications/8AAC5870-DF24-49BB-BCB8-598C8C0A7C9A/TestApp.app/test.html

Is there a way to preserve the hierachy? The reason i ask is my html file has references to the css like so:

<link rel="stylesheet" type="text/css" href="htmlcontent/test.css" media="screen, projector" />

As a result the css is not loaded. If I change it to the following:

<link rel="stylesheet" type="text/css" href="test.css" media="screen, projector" />

it loads.

Any thoughts?

Scoota P
  • 2,622
  • 7
  • 29
  • 45

1 Answers1

1

When you add files to your Xcode project, make sure you select "make folder references" instead of "make groups for folders"

However, shouldn't that be ,,/css/test.css ?

borrrden
  • 33,256
  • 8
  • 74
  • 109
  • Thanks that seemed to work. However, in my html file i have ../css/test.css and it isnt found. Does the relative pathing with .. work with IOS? – Scoota P Oct 23 '12 at 15:29
  • 1
    You need to make sure that you set the base URL of your web view (for example, in the function `loadHTMLString:baseURL:`). It should be the folder that your HTML is in. – borrrden Oct 23 '12 at 15:38