如何在UITableViewCell中刷新UIImage?

Che*_*rif 2 objective-c uitableview uiimageview ios swift

这就是我创建单元格的方式:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("FbFriendCell") as! FbFriendCell
        cell.initialize()
        return cell  
}
Run Code Online (Sandbox Code Playgroud)

非常简单.

在initialize()函数中,我下载了一个图像,并将其放在UIImageView中:

let theImageView = UIImageView(image: userPhoto)
theImageView.frame = CGRect(x: 0, y: 0, width: 80, height: 80)
self.addSubview(theImageView)
theImageView.image = userPhoto
println("The image has been set !")
Run Code Online (Sandbox Code Playgroud)

问题是图像仅在此日志消息后几秒出现:

println("The image has been set !")
Run Code Online (Sandbox Code Playgroud)

如何强制图像重新加载?

*阅读这个* =>问题可能与图像在UITableViewCell内部的事实密切相关!

Leo*_*Leo 6

确保更新主队列上的图像

 dispatch_async(dispatch_get_main_queue(), { () -> Void in
            //Update UI
 })
Run Code Online (Sandbox Code Playgroud)

我之前有这个问题,这解决了我的问题.试试吧