views:

18

answers:

1

I have implemented a standard UITableViewController. I have made only some rows in the table to be moveable, ie. canMoveRowAtIndexPath returns true only for some indexPaths (for rows in the first part of the table). I would like to allow exchange of only those rows that are moveable, ie. for which canMoveRowAtIndexPath returns true.

Eg. my table looks like this:

Row 1
Row 2
Row 3
Row 4
Row 5

Rows 1, 2, 3 are moveable. So I want to implement the following behavior: row 1 can be exchanged only with rows 2 or 3. Similary, row 2 can be exchanged only with rows 1 and 3. This is one possible layout:

Row 3
Row 1
Row 2
Row 4
Row 5

However, I don't want this to happen:

Row 3
Row 5
Row 2
Row 4
Row 1

How to achieve this?

+1  A: 

Keep in mind that it's actually only moving one row, not exchanging.

What you want is to implement tableView:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath

See http://stackoverflow.com/questions/849926/how-to-limit-uitableview-row-reordering-to-a-section

Eiko
Thanks a lot! targetIndexPathForMoveFromRowAtIndexPath solved my problem.
so you should accept Eikos answer
vikingosegundo