Reputation: 915
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; if(row == 0) return NO; return YES; }
My problem is: although i specified NO for row 0. If I attempt to drag row 1 to replace row 0, the animation lets this happen anyways. The problem is that the above method only decides whether or not there is a move icon on the right of the row. Any ideas on how to stop row 0 from ever getting replaced?
Upvotes: 2
Views: 1410
Reputation: 8412
Use
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
from the UITableViewDelegate
.
You can do something like this:
if ([proposedDestinationIndexPath row] > 0) {
return proposedDestinationIndexPath;
}
NSIndexPath *betterIndexPath = [NSIndexPath indexPathForRow:1 inSection:0];
return betterIndexPath;
(From "iPhone Programming" by Joe Conway & Aaron Hillegass)
Upvotes: 4