views:

135

answers:

2

I have a local HTML page which doesn't has any external link(css or images..)

I use method below to load it to a WebView

- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;

it takes around 5-8 seconds to load this page, that's too slow. right?

but when I load that page in iPhone safari, it takes around 2 second.

I don't know why it is slow like that in my WebView.

I also did a Google search, but I couldn't find any answer.

A: 

To load local html file you should try this:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];
Ruchir Shah
what is difference?, don't worry the time to load a local file to a NSData object.Actually, sometimes I save the html page to DB as a binary field. it looks like I have to use NSData.
owen
A: 

If you have the HTML as text then use the loadHTML:

[webView loadHTMLString:@"<html><body>Some HTML</body></html>" baseURL:nil];

It loads about 2 seconds for me (simple HTML).

Maybe you have some very large HTML and you read it from file?

Michael Kessler
I think 2 seconds is still slow for simple local html page.also, I have to use NSData because I don't know the encoding of the page.
owen