Reputation: 534
I have a UITableView that reads data from a sql db.
When i reorder the data it only changes the top and bottom ones
Dragging 1 from top to bottom
When i let it go at 5 it only switches the top and bottom ones.
I am using the following
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
[myStringsArray exchangeObjectAtIndex:fromIndexPath.row withObjectAtIndex:toIndexPath.row];
}
How can i reorder the list? So it'll be 2,3,4,5,1 and not 5,2,3,4,1
Upvotes: 1
Views: 979
Reputation: 6342
Exchange is not a proper way to do it you should use this.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
id buffer = [myStringsArray objectAtIndex:fromIndexPath.row];
[myStringsArray removeObjectAtIndex:fromIndexPath.row];
[myStringsArray insertObject:buffer atIndex:toIndexPath.row];
}
Edited to match comment below.
Upvotes: 5