3

I have a UITableView that I want to have respond to taps and vertical swipes, but still have something like userInteractionEnabled = NO for horizontal swipes. By that I mean, it would not handle touches and pass the touch event back to its superview.

Things I've tried that didn't work:

  • returning NO in - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

  • Overriding touchesBegan/touchesMoved/touchesEnded and passing the event to the next responder

  • Adding gesture recognizers for horizontal swipes and setting cancelsTouchesInView to YES

I've been trying to fix this on and off for several weeks, so any help is greatly appreciated!

D-Nice
  • 4,772
  • 14
  • 52
  • 86
  • What do you want the swipe to do? Since a swipe is a discrete gesture, what is it that you need to pass to the superview? – rdelmar Nov 03 '13 at 03:28
  • I want the entire swipe gesture to be passed to the superview. The UITableView is inside an iCarousel view, which is essentially a horizontal scrollview. I want the iCarousel view to handle horizontal swipe gestures that are currently being handled by the UITableView. – D-Nice Nov 03 '13 at 20:18
  • I answered, but to have more specific information I suggest you to add other details – LombaX Nov 09 '13 at 15:47

4 Answers4

2

better you can subview empty view for tableview.view color should be empty and add gesture to that view.if gesture direction is vertical.scroll tableview

0

Did you try just adding a horizontal swipe gesture recognizer to your table view's parent view? Also turn off horizontal scrolling on your table view. (set alwaysBounceHorizontal=NO)

nielsbot
  • 15,922
  • 4
  • 48
  • 73
  • Vertical scrolling is needed on the tableview. The tableview's parent view already responds to horizontal swipes, they've just being intercepted by the UITableView, which is what I'm trying to prevent. – D-Nice Nov 05 '13 at 02:15
  • sorry, I meant turn off _horizontal_ scrolling on your table view. – nielsbot Nov 05 '13 at 02:18
  • Also, try answering `NO` to `-tableView:canEditRowAtIndexPath:` in your table view delegate. – nielsbot Nov 05 '13 at 02:19
  • How can I turn off horizontal scrolling in the tableview? I've tried returning NO to that delegate method. No difference made. – D-Nice Nov 05 '13 at 04:50
0

Disabling user's interaction for each table view cell should help. I suggest doing it in cellForRowAtIndexPath method.

Sviatoslav Yakymiv
  • 7,887
  • 2
  • 23
  • 43
-1

The answer to this question is not simple, because UITableView manages a lot of touches, and this touches are managed by different components. So, to give you a correct and working answer, you have to explain:

  • what kind of swipes you want to disable (left-to-right, right-to-left)
  • where (on the empty table view, on the cell)
  • what happens now when you do this swipe (the cell goes in edit mode, a navigation controller goes to the previous page ecc....)

For example: the swipe-to-delete on a UITableViewCell can't be avoided by overriding touchesBegan:withEvent, because the touch is received by the internal content view (UITableViewCellContentView private class, so you can't subclass and override touchesBegan:withEvent). But this is not necessary, because you can disable this behavior adding this method to UITableViewController:

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone;
}

When you disable the editing (for example) the cell and the table view are no more capable of managing the touch, so the touch is forwarded to the next responder in the chain.

This is only one example, you must explain all the cases that are giving you undesider behavior to let us help you more.

Last suggestions: At this Page you will find a very good and interesting explanation on how the hit test end event handling process works. I'll update the answer with more specific information when you'll add more details.

Regards

Fabio

LombaX
  • 17,265
  • 5
  • 52
  • 77