0

I have a table view. And I have multiple rows. While doing the reorder in editing mode, I want one row to stay in the first index all the time. So, if a user wants to swap a row with the first row, it shouldnt allow it. But it should be possible between the second and the third row.

How can I do this? Thank you very much in advance

BPL
  • 277
  • 1
  • 3
  • 4

1 Answers1

2

Set the first table view cell's showsReorderControl to NO and return NO in tableView:canMoveRowAtIndexPath: for the first row.

You can also implement the UITableViewDelegate method tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:

Here you can return an alternate index path if the proposed one is (0, 0).

Return Value

An index-path object locating the desired row destination for the move operation. Return proposedDestinationIndexPath if that location is suitable.

Discussion

This method allows customization of the target row for a particular row as it is being moved up and down a table view. As the dragged row hovers over a another row, the destination row slides downward to visually make room for the relocation; this is the location identified by proposedDestinationIndexPath.

DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • Thank you very much DrummerB. The first option didn't work at me. I had already tried it. But the second one with "targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:" worked perfect. Thanks again – BPL Jul 02 '12 at 15:35
  • Yes, the first option just hides the reorder control on the first cell, so you can't move it. But you still have to implement the delegate method to prevent an other cell from being moved to the first row. – DrummerB Jul 02 '12 at 15:41