7

I would like to display HTML files included in an application bundle, but when I go to create a new document, I don't clearly see how to include HTML, except as an empty document.

What's a correct "<p>Hello, world!</p>" for, ideally, including HTML files as resources?

Thanks,

Christos Hayward
  • 5,777
  • 17
  • 58
  • 113

2 Answers2

13

From here: Load resources from relative path using local html in uiwebview

Drag the resource into your xcode project (I dragged a folder named www from my finder window), you will get two options "create groups for any added folders" and "create folders references for any added folders". Select the "create folder references.." option. Use the below given code. It should work like a charm.

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
[webview loadRequest:[NSURLRequest requestWithURL:url]];

Now all your relative links(like img/.gif, js/.js) in the html should get resolved.

Community
  • 1
  • 1
Woodstock
  • 22,184
  • 15
  • 80
  • 118
2

AFAIK there is no HTML file template and neither decent HTML editing capabilities in Xcode. So I suggest to edit the HTML files with another editor and add them to your project - you can either drag & drop or use right click and "add files to ...".

e1985
  • 6,239
  • 1
  • 24
  • 39