I’ve got a table with 3 sections and the model I’m using is defined as playingList : [[Player]]
. In my situation
playingList[0] = players are playing
playingList[1] = players are substitutes
playingList[2] = players are injured/unavailable
I’ve managed to move my uitableviewcells through sections, but struggling to update the model, the method I thought I needed doesn’t seem to be called. These are the methods I have around this, I obviously don’t quite understand them or am missing something
// delegates for re-ordering
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle
{
if (false == self.editing){
return UITableViewCellEditingStyle.None;
}
if (self.editing && indexPath.row == orderedPlayers.count){
return UITableViewCellEditingStyle.Insert;
}
else {
return UITableViewCellEditingStyle.Delete;
}
}
// Update the data model according to edit actions delete or insert.
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
{
/*if editingStyle == UITableViewCellEditingStyle.Delete{
orderedPlayers.removeAtIndex(indexPath.row);
playerTableView.reloadData();
}*/
// arbitrarily define two indexPaths for testing purposes
let fromIndexPath = NSIndexPath(forRow: 0, inSection: 0)
let toIndexPath = NSIndexPath(forRow: 0, inSection: 1)
// swap the data between the 2 (internal) arrays
let dataPiece = playingList[fromIndexPath.section][fromIndexPath.row]
playingList[toIndexPath.section].insert(dataPiece, atIndex: toIndexPath.row)
playingList[fromIndexPath.section].removeAtIndex(fromIndexPath.row)
// Do the move between the table view rows
playerTableView.moveRowAtIndexPath(fromIndexPath, toIndexPath: toIndexPath)
}
The above method doesn’t seem to be called as I tried to print details from this method to the console. What do I need to do to update my data Model to accurately reflect where an item is in an array of arrays?