Correct way to load image into UIWebView from NSData object

I tested the code with PNG (“image/png”), JPG (“image/jpeg”) and GIF (“image/gif”), and it works as expected:

[webView loadData:imageData MIMEType:imageMIMEType textEncodingName:nil baseURL:nil];

Now, what’s wrong with your app?

  • the imageData is not a well-formed image data. Try opening the file with a web browser or an image editor to check it.
  • the MIME type is incorrect. Look at the first bytes of the data to determine the actual file type.
  • webView is not connected in IB, is nil, is hidden, is covered with another view, is off screen, has a CGRectZero frame, etc.

Leave a Comment