开发者

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]]];
开发者_如何学Python

Thanks


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) { ... }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜