I'm trying to load image(s) from remote url, after the image has been loaded, I assign it to UIImageView
on a custom cell inside UITableViewController
:
func loadImage(url: NSURL) {
self.myImageView?.contentMode = UIViewContentMode.ScaleAspectFit
let queue = dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATED.value), 0)
dispatch_async(queue) {
if let imageData = NSData(contentsOfURL: url) {
dispatch_async(dispatch_get_main_queue()) {
self.myImageView?.image = UIImage(data: imageData)
}
}
}
}
It runs good, except that myImageView
does not load the image (I know it's asynchronously loading the image from the remote location), but if I click the cell or rotate the iphone simulator
, it shows the image. Any idea why this happens?