Correct way to load image into UIWebView from NSData object

前端 未结 10 2063
北恋
北恋 2020-12-03 05:26

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 U

10条回答
  •  [愿得一人]
    2020-12-03 05:59

    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.

提交回复
热议问题