Reputation: 213
I want to display some html content data in webview. For displaying html data, i have one html file, but i dont know how to execute that html in webview. Please guide me if any one knows.
Thanking in advance
Upvotes: 1
Views: 3041
Reputation: 23510
This is a too simple code and you will be limited very soon using it.
For example if you want to display images coming from your project bundle.
Prefer (if you use a HTML file) :
NSStringEncoding encoding;
NSError* error = nil;
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
NSString* htmlPath = [[NSBundle mainBundle] pathForResource:self.htmlFilename ofType:@"htm"];
NSString* htmlContent = [NSString stringWithContentsOfFile:htmlPath usedEncoding:&encoding error:&error];
if (error != nil) // Manage the error
[webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:bundlePath]];
or shorter for direct HTML inline coding :
NSString* htmlContent = @"<html><head><title></title></head><body><img src='image.jpg' /></body></html>";
[webView loadHTMLString:htmlContent baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
Upvotes: 1
Reputation: 22334
Use the loadString method...
[webView loadHTMLString:myHtmlString baseURL:nil];
Upvotes: 4