UIImageView仅在单击/旋转时显示图像

时间:2015-07-17 18:33:22

标签: ios swift uitableview uiimageview grand-central-dispatch

我尝试从远程网址加载图片,在加载图片后,我将其分配到UIImageView内的自定义单元格上的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)
      }
    }
  }
} 

它运行良好,除了myImageView没有加载图像(我知道它是从远程位置异步加载图像),但如果我单击单元格或旋转{{1} },它显示图像。知道为什么会这样吗?

0 个答案:

没有答案