Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh an UIImage in an UITableViewCell?

This is how I create my cells :

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

        let cell = tableView.dequeueReusableCellWithIdentifier("FbFriendCell") as! FbFriendCell
        cell.initialize()
        return cell  
}

Very simple.

In the initialize() function, I download an image and I put it in an 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 !")

The problem is that image only appears several seconds after this log message :

println("The image has been set !")

How can I force the image to reload ?

* READ THIS * => The issue could be strongly related to the fact that the image is inside an UITableViewCell !

like image 428
Cherif Avatar asked Jan 17 '26 06:01

Cherif


1 Answers

Make sure you update the image on main queue

 dispatch_async(dispatch_get_main_queue(), { () -> Void in
            //Update UI
 })

I have this issue before,and this solve my problem.Just try

like image 96
Leo Avatar answered Jan 19 '26 20:01

Leo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!