Correct way to load image into UIWebView from NSData object

Posted by rustyshelf on Stack Overflow See other posts from Stack Overflow or by rustyshelf
Published on 2010-05-13T15:13:12Z Indexed on 2010/05/14 1:34 UTC
Read the original article Hit count: 593

Filed under:
|
|

I have downloaded a gif image into an NSData object (I've checked the contents of the NSData object and it's definitely populated). Now I want to load that image into my UIWebView. I've tried the following:

[webView loadData:imageData MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

but I get a blank UIWebView. Loading the image from the same URL directly works fine:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]];
[imageView loadRequest:request];

Do I need to set the textEncodingName to something, or am I doing something else wrong?

I want to load the image manually so I can report progress to the user, but it's an animated gif, so when it's done I want to show it in a UIWebView.

Edit: Perhaps I need to wrap my image in HTML somehow? Is there a way to do this without having to save it to disk?

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about uiwebview