daltoniam / Skeets

Fetch, cache, and display images via HTTP in Swift.
Apache License 2.0
191 stars 21 forks source link

Cell images only visible after refreshing tableView #14

Closed Knights22 closed 9 years ago

Knights22 commented 9 years ago

When downloading the data, cell.textLabel!.text will be present but cell.imageView?.image will not show the images unless i run tableView.reload() again. Any reasons why? This is under protocol, func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

ImageManager.fetch(user.profilePic, progress: { (progress: Double) in
                    }, success: { (data: NSData) in
                        cell.imageView?.image = UIImage(data: data)
                        println("image loaded")

                    }, failure: { (error: NSError) in
                        println("failed to get image: \(error)")
                })
daltoniam commented 9 years ago

Hmm, not sure why that would be the case, it should work fine. I have an example app that does the same thing and it works properly:

https://github.com/Vluxe/SwiftPeople/blob/master/SwiftPeople/ViewController.swift

http://vluxe.io/build-swift-people.html

Knights22 commented 9 years ago

Thanks i just took a look at it, 2 points, is this line of code compulsory: 1)

 //if the cell is being recycled, make sure to cancel the old url it was loading.
            if cell.currentImgUrl != "" {
                ImageManager.cancel(cell.currentImgUrl)
            }
            //

2) I was using the default cell but will create a custom cell and see how it behaves, nobody else seems to ave this issue so it must be on my side, i hope. Thanks for the quick reply.

daltoniam commented 9 years ago

welcome :+1: