moon moon - 2 years ago 100
Objective-C Question

how to tag UIImage in UITableViewCell

I want to toggle UITableViewCell image - cell.imageView.image. (eg. Red <--> Green)

If the current image is green, the image suppose to change to Red when the user click the UITableViewCell.

Once I set the image

cell.imageView.image = [UIImage imageNamed:@"Green.png"];

How to detect which image is the cell currently using?

Thanks for any help!

Answer Source

It's a bit crude, but you should be able to set up an if statement like the following:

if ([cell.imageView.image isEqual:[UIImage imageNamed:@"Green.png"]]) {
    // image is green;
} else {
    // image is red;

I tested it out just to make sure and it works fine

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download