i have modified your code , check it
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PlacesCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"PlacesCell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
//Create ImageView
cell.imageView.image = [UIImage imageNamed:@"checkmark.png"];
//Add Gesture Recognizer
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTapped:)];
tapped.numberOfTapsRequired = 1;
[cell.imageView addGestureRecognizer:tapped];
cell.imageView.userInteractionEnabled = YES;
//[cell addSubview:cell.imageView];
return cell;
}
//Method controlling what happens when cell's UIImage is tapped
-(void)imageTapped:(UIGestureRecognizer*)gesture
{
UIImageView *selectedImageView=(UIImageView*)[gesture view];
UIImage *imageDefault = [UIImage imageNamed:@"checkmark.png"];
UIImage *imageRed = [UIImage imageNamed:@"checkmark(red).png"];
UIImage *imageGreen = [UIImage imageNamed:@"checkmark(green).png"];
if (selectedImageView.image == imageDefault) {
selectedImageView.image = imageGreen;
//cell.selected = true;
NSLog(@"Selected");
} else {
selectedImageView.image = imageRed;
//cell.selected = false;
NSLog(@"Deselected");
}
}