user601367
user601367

Reputation: 2368

how do i add html page in my iphone xcode project?

can anyone tell how to add html in my iphone project?? And their is no html option which i click on add new file in class group...why is that???

Upvotes: 6

Views: 13572

Answers (3)

Xiao Xiao
Xiao Xiao

Reputation: 941

simply create a blank file and rename it to html or add existing html file to the project. the next step depends on how you wish to use the html file.

Say if you want to load a local file called page.html, first you add the file to project,and in the build phases of your project, and the page.html to Copy Bundle Resources, and run this in your app, it writes the file to the documents dictionary of your app/

NSString *Html = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"page" ofType:@"html"] encoding:NSUTF8StringEncoding error:NULL];
[Html writeToFile:[[self docPath]stringByAppendingPathComponent:@"page.html"] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
[Html release];

and your webview should call this to load the file:

NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [docPaths objectAtIndex:0];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[docPath stringByAppendingPathComponent:@"page.html"]]]];

and it's done.

Upvotes: 8

Robin
Robin

Reputation: 10011

You can use UIWebView to show your html file like this

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString]];
[webView loadRequest:request];

where URLString contains is your file url.

Upvotes: 0

hotpaw2
hotpaw2

Reputation: 70703

What you might be looking for is documentation and example code for the UIWebView class of UIKit.

Upvotes: 0

Related Questions