Save new cell position after reorder and affect the model (datasource)

0

I need the implementation of a tableview, where I can rearrange the cell positions and save them in the new order. And this new order should affect the order that they are saved also the model (in this case an NSMutableArray or NSMutableDictionry).

I'll put the image below to illustrate better:

    
asked by anonymous 14.09.2014 / 19:32

1 answer

1

In% w_that implements the% com_view controller associated with the table), you need to implement the selector @interface . In the implementation you need to change the order of the elements of your UITableViewDataSource (geralmente o , as in the example below:

- (void)   tableView:(UITableView *)tableView
  moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath
         toIndexPath:(NSIndexPath *)destinationIndexPath
{
    NSInteger fromIndex = sourceIndexPath.row;
    NSInteger toIndex = destinationIndexPath.row;
    if (fromIndex == toIndex) return;

    id item = [self.items objectAtIndex:fromIndex];
    [self.items removeObjectAtIndex:fromIndex];
    [self.items insertObject:item atIndex:toIndex];
}
    
15.09.2014 / 05:26