onevcat / Kingfisher

A lightweight, pure-Swift library for downloading and caching images from the web.
MIT License
23.36k stars 2.66k forks source link

TableView cells in Container only loading first image #476

Closed uknowmeright closed 7 years ago

uknowmeright commented 8 years ago

So I have a ContainerView that is contains a UITableviewController. In the UITableviewController I am using this code:

            let cell = tableView.dequeueReusableCellWithIdentifier("UserSearchCell", forIndexPath: indexPath) as! UserSearchCell
            let user = tableUsers[indexPath.row]
            cell.userLabel.text = user.cell!

            if (!UIAccessibilityIsReduceTransparencyEnabled()) {
                cell.backgroundColor = UIColor.clearColor()
                let blurEffect = UIBlurEffect(style: .Light)
                let blurEffectView = UIVisualEffectView(effect: blurEffect)
                cell.backgroundView = blurEffectView

                cell.selectedBackgroundView = blurEffectView
            }

            dispatch_async(dispatch_get_main_queue(),{
                let downloadableUrl = "https://" + Helpers().getCDN()! + "/users/" + user.user_id! + "/photo/thumbs/" + user.photo! as String
                print(downloadableUrl)
                cell.userPhoto.kf_setImageWithURL(NSURL(string: downloadableUrl), placeholderImage: UIImage(named: "noavatar"))
            })

            return cell

Now the first Cell Image loads, however, the rest of Cells all have the SAME image. I have tried running dispatch_async(dispatch_get_main_queue(),{ }) in multiple places for fear of it being a thread issue but still have had no luck. Any Ideas what might be causing this?

Thanks in advance!

onevcat commented 8 years ago

There should be no need to run with dispatch_async. However, I have no idea about what causes it. The code seems good to me and it should work if you have correct model.