简体   繁体   中英

Check if image is empty for reused cells

Each cell has an image. I want to be able to check if the image is empty.

I am using tableView's reuseIdentifier .

I have tried to do the following

if (!cell.imageView.image) {

}

and

if (CGSizeEqualToSize(cell.imageView.image.size, CGSizeZero)) {

}

But none of these approaches work, as the cell thinks the image exists, because previous cell's images exist (due to reused cells)

How do I get around this problem? How do I check if a cell's image is empty or not in a reused cell?

Technically if the cell is reused, the image won't be nil (unless you didn't set it). So if you want to not reuse the images from your cells you can use -prepareForReuse method from UITableViewCell, this method is called right before the cell is reused, so in this method you can make the image nil.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM