navigator48
navigator48

Reputation: 217

UITableView cell reordering drag action unexpectedly stops

I'm trying to figure out how to debug the following scenario to understand why UITableView cells won't re-order.

  1. Touch 'Edit' menu item, to put table view into edit mode.
  2. Edit mode works for deleting cells.
  3. Try to re-order cells by touching and dragging the re-order control on a cell.
  4. Cell outline moves in the drag direction a couple of pixels, but then snaps back into it's original position even through my finger is still dragging across the screen.

In code:

The same view controller code and storyboard work correctly for reordering cells in another project.

I've searched stackoverflow and Google for a day and can't find any reference to what would cause a cell drag event to get canceled.

Any thoughts on how I could approach debugging this issue would be greatly appreciated!

Upvotes: 5

Views: 988

Answers (2)

ConfusionTowers
ConfusionTowers

Reputation: 961

I experienced the same issue, and found the solution in my case was to add the various swipe & tap gestures on my tableview cells NOT to the cell itself, but to the contentView of the cell.

So, rather than this,

cell.addGestureRecognizer(myGesture)

the code becomes

cell.contentView.addGestureRecognizer(myGesture)

And that seems to work well, fixing the same sort of herky-jerky scrolling that the OP had. Perhaps somebody can benefit from this solution, if your issue is more like the one I was having than the one the OP had.

Longer discussion of the solution can be found here: Add a gestureRecognizer to a tableView cell

Upvotes: 1

navigator48
navigator48

Reputation: 217

I found the answer, and it had nothing to do with the UITableView code.

My code has a programmatically created root view controller that handles showing/hiding a sliding menu panel.

The viewDidLoad() of this view controller creates a panGestureRecognizer to track swipes for showing/hiding the sliding menu. This panGestureRecognizer was not passing through touches.

Adding this code fixed the problem:

panGestureRecognizer.cancelsTouchesInView = false

Upvotes: 7

Related Questions