Joe Shamuraq
Joe Shamuraq

Reputation: 1385

Error implementing UIWebView to load local html

am trying to add a UIWebView to my current UIScrollView. The UIWebView is supposed to access a local html file 'index.html'. I got an error at runtime:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

This is my code:

UIWebView *webView = [[UIWebView alloc] initWithFrame:scrollViewFrame];
    NSString *indexPath = [NSBundle pathForResource:@"index" ofType:@"html" inDirectory:@"Addition"];
    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:indexPath]]];

I do have 'Addition' folder (not group; imported from 'Add' in my project).

Thanx in advance...

Upvotes: 0

Views: 575

Answers (1)

Mundi
Mundi

Reputation: 80271

Did you check indexPath with a breakpoint or NSLog? It looks like your file is not there (perhaps a typo?)-

EDIT

OK, I just tested this successfully. Try this:

  1. Delete all the web files from your project.
  2. Copy the web directory into the right place in your project folder.
  3. Drag from Finder to Xcode, do not copy, Create folder references

One more caveat: Maybe there is a difference in capitalized resource names between the simulator and the device. Try using lowercase throughout.

Also, you should perhaps correct your command pulling the resource from the bundle. Instead of

[NSBundle pathForResource...

it should be

[[NSBundle mainBundle] pathForResource...

Upvotes: 2

Related Questions