How do i check if the UIImageView did fail to load the image ?
I have a UIImageView loading an image from URL like so:
[MyImageView setImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://exampleUrl.com/images/the_image.png"]]]];
but if the image for some reason is not available i want to load an alternative image.
How would i approach this problem ? Can i add some kind of observer ?
Alternatively can i check when the ImageView did finish loading the image to check if the image is nil ?
Thanks !
You are making a synchronous request on main thread and not even checking error conditions like if it fails or network connection times out.
You can use this instead:
Using Asychronous url load using NSURLConnection. When connection has finished downloading data or error occured it notifies via connection handler block.