0

I have added an .html, two .js and one .css file in my project and I have used following code with UIWebView for accessing the .html file

[web1 loadRequest:[NSURLRequest requestWithURL:
                           [NSURL fileURLWithPath:[[NSBundle mainBundle]

pathForResource:@"index" ofType:@"html"] isDirectory:NO]]];

Where web1 is my UIWebView and it is synthesized. Now when I open that page, it is without any CSS, just lines and links in order and no decoration.

And also when I click on any link, it does not show me my expected results, because .js is not working (or I should say, they are not being found by xcode, though I have added them with normal files as well as with frameworks).

3
  • How did you include the css and js files in the html file? What do you mean with "not found by Xcode"? Commented Apr 1, 2013 at 15:16
  • i have add css and java file like this <head> <link rel=stylesheet type="text/css" href="css/layout.css"> <script type="text/javascript" src="java/script.js"></script> i have try this also <link rel=stylesheet type="text/css" href="layout.css"> <script type="text/javascript" src="script.js"></script> i mean xcode don;t run js and css file just run the html file without css and js.. Commented Apr 1, 2013 at 15:21
  • @ranakhan Please be a little more polite. People are just trying to help. Maybe d4Rk needed to go away for, whatever reasons, making him not able to answer right now. Please be patient ;) Commented Apr 1, 2013 at 16:05

2 Answers 2

0

Please check the following things:

  • did you properly add the files to your projects resources?
  • are they included in your targets build phases?

If you are sure about this, and it's still not working, I would recommend to try the following (which was working for me in the past)

UIWebView *webView = [[UIWebView alloc] init];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
NSString *htmlString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:[[NSBundle mainBundle] resourcePath]]];
Sign up to request clarification or add additional context in comments.

Comments

0

Check this answers, I think they may point you in the right direction:

UIWebView doesn't load external Javascript file

iPhone UIWebView local resources using Javascript and handling onorientationChange

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.