Mikechina
Mikechina

Reputation: 21

UiWebView How to load local html in a state where there is no network

novice help, listen to people say UiWebView can load a local html file, I have a web application html + js can be run from a web page and want to run into the ipad.

if anyone knows, please express specific operation. Extremely grateful stackoverflow first post.

Upvotes: 2

Views: 260

Answers (1)

Adro
Adro

Reputation: 675

Create a new Xcode project. Import your html, javascript, css, etc, file(s) to your Xcode Project, Add file(s) to Xcode Project

Select your html, javascript, css, image, etc file(s)

Add UIWebView to your XIB, or storyboard. (As for me, I named it as webView - see figure) Add UIWebView and link and name it as you wish

Then in the UIViewController delegate method - (void)viewDidLoad

  • -(void)viewDidLoad { }

Put something like this:

NSURL *rootURL = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
    NSURLRequest *requestURL = [NSURLRequest requestWithURL:rootURL];
    [self.webView loadRequest:requestURL];

Run your project to test. As for me, this is the result:Ran on iPhone Simulator

Upvotes: 7

Related Questions