Toggle image display in UITableViewCell

Depending on the result of the condition, I want to display the UIImageView in the table cell. Otherwise, display a UITableViewCellAccessoryCheckmark. I would like to build a cell in IB. The part that I do not know what to do with UIImageView when I do not want it to be displayed. If I were developing everything programmatically, I would add a UIImageView as needed. But since this will be done in IB, UIImageView is always present. If you leave the cell alone by default (images are displayed), otherwise delete the UIImageView and display the UITableViewCellAccessoryCheckmark? If this is done, do I need a tag in UIImageView so that it can be retrieved and deleted?

+3
source share
1 answer

You can easily control the visibility of any control, including UIImageView. If you want to create things in IB, then one solution is to add the controls you need, set them as properties and hide the ones you do not want for this cell.

eg.

cell.image.hidden = YES;

When they are hidden, they have no overhead, and although there may be thousands of rows in your cell, there will be very few real cells, so this is a pretty effective solution. Just remember that cells are reused if you call [tableView dequeueReusableCellWithIdentifier] (what you need to do), so you will need to explicitly show / hide the control whose visibility can be changed.

. , , , , , .

+6

Source: https://habr.com/ru/post/1705360/


All Articles