4

I have two custom controls on my UIView, the one is the now popular sliding menu (when you slide the finger on the NavBar the view slides to the right) and the other one is on the UITableViewCell - it's a custom TableViewCell from the control named DMSlidingTableViewCell (Like in Twitter app - when you slide the cell on the left, it reveals some buttons, etc.)

They work just fine, but when I try to add a Gesture recognizer to the whole UITableView thus making the whole view a region for UIGestureRecognizer (so when I move it I can move the view to the right) the gestures recognizers somehow conflict.

What can be the reason here?

Sergey Grischyov
  • 11,995
  • 20
  • 81
  • 120
  • what gestures are you trying to recognize on the table cell and on the table as a whole? is it the same kind? different? – sergio Jan 15 '13 at 12:33
  • @sergio The gesture recognizers are both of SwipeGesture, but with or without the same direction, they just don't work. – Sergey Grischyov Jan 15 '13 at 12:35
  • 1
    check http://www.chewyapps.com/2012/10/26/swiping-on-a-uitableviewcell/ and http://kaihangjia.blog.163.com/blog/static/2145761562012111224644877/ – TonyMkenu Jan 15 '13 at 14:25

2 Answers2

6

I am not clear about the way you think that two swipe gesture recognizers could work together in that context, but I think you could try and give a look at the

– gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

delegate method.

Keep in mind that you have 2 gestures, so 2 delegate (conceptually, they be implemented by the same method), so you could make one gesture (first argument) always return NO, the other YES and see if you can make the 2 gesture recognizers work together in a satisfactorily way.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    if ([gestureRecognizer.view isKindOfClass:[UITableView class]]) {
       ...
    } else {
       ...
    }
}

This is just an example which should work in your case (check the syntax, though), but you could also store the 2 recognizers in properties of your class, so you know which one is which.

sergio
  • 68,819
  • 11
  • 102
  • 123
5

When I use UIGestureRecognizer on a UITableView, I met the same problem like u.Finally, I found the "cancelsTouchesInView" property in UIGestureRecognizer by this one,and its helpful.

  UIGestureRecognizer* tapGesture = [[UIGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
  **tapGesture.cancelsTouchesInView = NO;**//pass touch event to others

best wishes!

Community
  • 1
  • 1
iPanda
  • 61
  • 1
  • 3