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).

Sam R.
  • 16,027
  • 12
  • 69
  • 122
rana khan
  • 11
  • 4
  • How did you include the css and js files in the html file? What do you mean with "not found by Xcode"? – d4Rk Apr 01 '13 at 15:16
  • i have add css and java file like this i have try this also i mean xcode don;t run js and css file just run the html file without css and js.. – rana khan Apr 01 '13 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 ;) –  Apr 01 '13 at 16:05

2 Answers2

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]]];
d4Rk
  • 6,622
  • 5
  • 46
  • 60
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

Community
  • 1
  • 1
PakitoV
  • 2,476
  • 25
  • 34