Never use dataWithContentsOfURL to fetch a non-local URL. It is designed for loading data from files, not network URLs. Although it will load data from network URLs, it does so synchronously on the current thread, and if you're working with UIView objects, that means this is on the main thread.
If you do it the way you're trying to do this above, your app will get rejected from the App Store with almost 100% certainty, because on a slow network, the image loading will block long enough for iOS to kill your app outright for blocking the main thread for too long.
To make a network request, you must use NSURLSession
(or NSURLConnection
if you're trying to maintain backwards compatibility with iOS 6 and earlier) to retrieve the image, and then when the request finishes loading, create a UIImage
with that data and then call setImage
on an already-displayed UIImageView
(which should be showing some sort of "loading" icon up until that point).
It might be easier to use one of the many third-party networking libraries that provide classes specifically for the purpose of making network image loading less painful.
With that said, I don't see why your existing code doesn't show anything (assuming the server responds quickly enough) unless you have a problem with the bounds or with autolayout constraints causing the image view itself to not be visible or to be clipped.