0

My reusable cell contains a view with all its informations (UIImageView, UILabel, etc.) with a frame of 0,0,320,63, named mainView

I also have another subview, added programmatically, with a frame of -160,0,160,63, named leftView, contained in mainView.

I added a UISwipeGestureRecognizer to the cell, so when you swipe, I change the frame of mainView to 160,0,320,63. It works perfectly.

I just have a problem, in leftView, I have some UIImageView with userInteractionEnabled set to YES, with a gesture recognizer on it. But this gesture recognizer is never fired, it still calls the -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method.

I looked at this SO answer, but it does not help me.

Would somebody help me with that ?

Thank you !!

EDIT : Here is my gesture recognizer instantiation

// Selector is valid, I checked it out. _viewController too.
UIImageView * imageView = [[UIImageView alloc] initWithFrame:frame];
[imageView setImage:someImage];
[imageView setUserInteractionEnabled:YES];
[_leftView addSubview:imageView];
UITapGestureRecognizer * gr = [[UITapGestureRecognizer alloc] initWithTarget:_viewController action:selector];
[imageView addGestureRecognizer:gr];
Community
  • 1
  • 1
DCMaxxx
  • 2,534
  • 2
  • 25
  • 46

3 Answers3

2

Without seeing the gestureRecognizer's initialization, it could be a number of things that are the problem. Two main things to look into however:

1.) Have you set the cancelsTouchesInView flag? Normally this would be messing with your tableView touches, but you should look into it though.

2.) Have you verified the subview layout inside of storyboard? Is there something blocking part of your imageView?

-Also you've actually allocated the gestureRecognizer correct?

Tommy Devoy
  • 13,441
  • 3
  • 48
  • 75
  • Thanks for your help. `cancelTouchesInView` isn't set. The subview isn't added from the storyboard, because I need to set it's frame programatically. I added my gesture recognizer initialization in my post. – DCMaxxx Jul 04 '13 at 06:51
1

Have you tried to set table cell selectable to No? in this case your swipe gesture should still work, but table deligate method for cell selection shouldn't.

Ruben
  • 290
  • 3
  • 14
  • You mean by setting the userIteractionEnabled to NO on the cell ? If so, it doesn't work either. – DCMaxxx Jul 04 '13 at 06:40
  • No, I mean like this self.tableView.allowsSelection = NO; it will disable cell selection, and delegate method will not be called – Ruben Jul 04 '13 at 07:03
  • Just tried, it didn't work. But I found a solution, I just answered myself. Thanks anyway. – DCMaxxx Jul 04 '13 at 07:15
1

I figured it out myself.

The problem was because the leftView frame was outside of the mainView frame (-160 in x).

To solve my problem, I changed mainView in storyboard, so that it also starts at -160. And instead of adding leftView at -160 in x, I add it at 0.

Thanks anyway !

DCMaxxx
  • 2,534
  • 2
  • 25
  • 46