How to check if UIImage loaded from a URL is valid
Is there a way I can check if there is valid image in the NSData I've loaded into my UIImage object?
The UIImage is loading in from NSData dataWithContentsOfURL:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:MyURL]]];
开发者_如何学PythonThanks
see here.
Check if NSURL returns 404 
using NSURLConnection you can get the statuscode
It depends on what you mean by a valid image. If you do
[UIImage imageNamed:]
and the image isn't valid, it will return nil, so you can do:
UIImage *myImage = [UIImage imageNamed:@"yourImageName.png"]
if (myImage != nil) { ... }
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论