Using the provided reorderControls, the user can tap and hold to drag a cell around to reorder it. How can I know which cell they’ve selected to drag and the position of that current cell (ie when other cells animate to make room for the floating cell, I want the indices of the cells that moved)?
What I am trying to do is to scroll the view so that cells that are offscreen will be scrolled onscreen if the user wishes to reorder the current cell with an offscreen cell. I cannot use built in behaviour because my setup is:
UIScrollView (parent)
- UITableView (child)
And the UITableView frame is the full size of its contentSize (It does not scroll). I need to scroll the outside UIScrollView relative to where the user is dragging a cell to reorder in the UITableView.
I tried looking through the delegate and datasource functions but no luck so far. Also tried googling and Apple documentation…
Edit: SEEMS LIKE I CAN’T READ DOCUMENTATION. tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath: in the delegate protocol gives me what I need.
Solution: create a delegate fro tableview to the scrollview’s controller (my tableview is its own delegate). In the proposed index path function, I sent the delegate the cell near the proposedDestinationIndexPath that needs to become visible. This could be that cell itself if the indexpath is 0 or the max. Then in the delegate I calculate the position of that cell using the [view convertPoint:FromView:] function and set the scrollview’s content offset to make that cell visible!
Thanks
Normally, as you drag a cell, the table view automatically scrolls when you get to the top or bottom. It sounds like the use of the scrollview is preventing that from working properly since the table view thinks it is big enough not to scroll. There is no normal API call that will give you the answer you want.
The only thing I can think of that may get you close is the implementation of the
tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:table view delegate method.The
proposedIndexPathmay give you a rough idea where the user has currently dragged the row. You can use that indexPath to ask the table for theCGRectof the path. Then translate that to a position within the content view of the scroll view.This is far from perfect though.
Another possibility might be to add an observer to the
frameorcenterproperty of the cell being moved.