IPhone - detect UITableViewCell subheading touches

I am filling a UITableView with cells containing a subview UIImageView. I would like to detect strokes in the image, so I add a gesture recognizer to it as well. However, it causes nothing. Here is my code:

UIImageView *delete = [[UIImageView alloc] initWithFrame:CGRectMake(1.0, 8.0, 33.0, 33.0)];
delete.image = [UIImage imageNamed:@"Delete.png"];
delete.userInteractionEnabled = YES;
delete.contentMode = UIViewContentModeCenter;

UIGestureRecognizer *gesture = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(deleteTapped)];
gesture.delegate = self;

[delete addGestureRecognizer:gesture];
[self.cellView addSubview:delete];

      

Note. I technically add the image view to the container, which is then added to the cell itself hence [self.cellView addSubview:delete]

. But I had the exact same results adding the image to the cell directly.

According to this answer to a similar post, this is a known bug in iOS 5.0; the solution is to override the delegate method to force the gesture recognizer to start:

The fix is ​​to override -gestureRecognizerShouldBegin: in the gesture recognizer delegate and return YES. This bug should be fixed in a future iOS 5.x release. This is safe as long as you don't use the new copy / paste API for the UITableViewCell.

I tried this, but the delegate method was never called. I set a property delegate

(see above) and implemented <UIGestureRecognizerDelegate>

like this:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    NSLog(@"gesture delegate method called");
    return YES;
}

      

Does anyone have any ideas why this won't work anyway? Or is it possible that this status of this bug is in iOS 5.1?

+3


source to share


1 answer


try returning YES for this delegate method - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;



and if you want to detect tap action use UITapGestureRecognizer

+6


source







All Articles