Resolved allow dragging in table cell without overriding scrolling

Discussion in 'iOS Programming' started by straber, Jul 18, 2012.

  1. straber, Jul 18, 2012
    Last edited: Jul 25, 2012

    straber macrumors member

    Joined:
    Jul 3, 2012
    #1
    I have enabled dragging from a table cell by attaching a pan gesture recognizer to the label in each table cell. This works perfectly for letting users drag an item from the tableview over onto the main view, which is what I want, however this also causes the tableview to not scroll because the label is handling the drag motion instead of the tableview. Is there a way I can keep the dragging for horizontal movements, but have the tableview handle scrolling for vertical drags?
     
  2. MattInOz macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #2
    You can add a single Gesture to the tableView itself to detect the sideways swipes, allowing the vertical swipes to be still handled by the tableView.

    The trick is you then need then work out with the Tableview which cell is under the swipe. this handy blog article goes in to full detail.

    http://blog.blackwhale.at/?p=795

    I had it working with gesture recognizers in the cells before I found this, the tricky bit was making sure your gesture recognizer is passing through gestures event it doesn't recognize to the views below it. But if you can get the above to work for you it seems to work more reliably and smoothly when testing on the device.
     
  3. straber thread starter macrumors member

    Joined:
    Jul 3, 2012
    #3
    Thank you, MattInOz. This worked nearly perfectly. The only thing I had to change was that I had to add a gesture to the textLabel in each table cell, adding just one to the table worked, but it would only allow me to drag around inside the table, once I hit the border of the table, the text would stop there as my finger continued dragging. Other than that, works like a charm!
     

Share This Page