Reputation: 198
I have custom UITableViewCell:
Also have some objects (get from server) with imageURL property.
Task: Need asynchronous download images (via Kingfisher). If image not exist - hide ImageView. Some works fine, BUT:
When images begin downloading (in background), user also can scroll tableView, and if image not downloaded (image == nil), imageView hiding (need hide/show), and contentSize in scrollView changed. - problem FIRST (scroll jump)
SECOND: When user scrolling filled tableView, some cells not have images, and when this cell reused, Kingfisher also trying download image for reused cell. If image exists - imageView showing, and cell like as expand. Again scrollview contentSize changed, and in result we have glitches jumps.
P.S. Tried use tables updates, reload row, also use different cell for empty cell - not successfully. Also tried find solution in SO, but funded only theory :)
Have ideas (not only be theory)?
Thanks
P.S.S. Hardcoded cell sizes based on images (have or not). And also change constraint imageView (0 or xxx). If understand right - tableView don't know cells sizes (because was set UITableViewAutomaticDimension)
Not GOOD solution, but works.
Upvotes: 2
Views: 441
Reputation: 25261
For your first problem, there are two ways to solve it. You can either have a super fast server, or preload image height in your arrayOfObjects. That is, when you get your list of objects, you also check if there is an image. So when you load the cell, you don't need to wait for the download and then show/hide the image. Doing this not only make the scroll better, but also reduce calls to the image server.
For your second problem, have a flag in your object from the array indicating if the object has an image or not. And if it does not have image, stop downloading again from the server. A sample code will look like this:
//itemObject now has property called loadFlag which set to true by default
if itemObject.loadFlag {
//Your loading image code . If image is nil, set this flag to false
} else { //This will prevent reused cell having image by default
cell.pictureView.isHidden = true
cell.picture = nil
}
Upvotes: 0