У меня есть изображение внутри каждой ячейки моего контроллера представления таблицы и распознавание жестов Tap. Это работает нормально и соответствующим образом регистрируется. Другими словами, сначала это серый список, затем вы нажимаете на изображение, изображение превращается в зеленый контрольный знак, снова нажмите, оно превращается в красный X. Поэтому в противном случае полезные потоки, подобные этому, не работают для меня. < /P>
Вот код: < /p>
- (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
{
UITableViewCell *cell;
UIImage *imageDefault = [UIImage imageNamed:@"checkmark.png"];
UIImage *imageRed = [UIImage imageNamed:@"checkmark(red).png"];
UIImage *imageGreen = [UIImage imageNamed:@"checkmark(green).png"];
if (cell.imageView.image == imageDefault) {
cell.imageView.image = imageGreen;
cell.selected = true;
NSLog(@"Selected");
} else {
cell.imageView.image = imageRed;
cell.selected = false;
NSLog(@"Deselected");
}
}
Подробнее здесь: https://stackoverflow.com/questions/218 ... age-on-tap