3

I'm using a UIWebview to display content provided within local HTML files.

The problem however is that the page is not displaying correctly, only the core html is rendered with no css styles or media content displayed. For this project, I have the entire web structure in their respective folders and are placed within the Xcode project (all content is displayed within blue folders).

The built application package contains the web folders and all of content is there so I am unsure as to why it is not displaying correctly.

Here is the code I am using to load and display the webpage:

NSString *html = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"www/content/island-1" ofType:@"html"] encoding:NSUTF8StringEncoding error:NULL];


NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:html baseURL:baseURL];

within the html files, here are code references to some content:

<script type="text/javascript" src="../static/js/custom-event.js"></script>

<script type="text/javascript" src="../static/js/touch-source/Browser/Features.Touch.js"></script>

<link rel="stylesheet" href="../static/css/islands_popup.css">
<link rel="stylesheet" href="../static/css/content.css">

All folders and files are correct and none are missing. Does anyone know what I might be doing wrong?

1
  • 1
    Please your .js and .css file is added in your project folder Commented Jul 24, 2012 at 10:40

2 Answers 2

2

XCode doesn't use folders, it use just its bundle to store all data. So I would advise you to use:

 <script type="text/javascript" src="custom-event.js"></script>  

Instand of:

<script type="text/javascript" src="../static/js/custom-event.js"></script>.

Same with your css and other files. Also if we talk about .js files be sure to delete files from::

Targets-->Build Phases--->Compile Sources

and add to

Targets-->Build Phases--->Copy Bundle Resources

Because when you first add .js files to project XCode somehow thinks it needs to be compiled.

Sign up to request clarification or add additional context in comments.

Comments

0

Are your relative references (i.e. "../[directory]/[filename]") correct?

Personally I avoid these relative source references and instead go with root relative: i.e. /[directory from root of website]/[file name]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.