I have one tableview with two sections: ingredients to buy and ingredients that user has already. So, basically when uses does shopping he/she passes one ingredient from one list to another.
I will call this one: (I included stateOfCheckbox - every tableviewcell includes a custom button with a role of a checkbox - basically this one gives me the direction from/to I will do the move).
func doChange(stateOfCheckbox: Bool, row: Int){
let fromSection = stateOfCheckbox ? 0 : 1
let toSection = stateOfCheckbox ? 1 : 0
let fromIndexPath = NSIndexPath(forRow: row, inSection: fromSection)
let toIndexPath = NSIndexPath(forRow: 0, inSection: toSection)
let dataPiece = ingredients[fromIndexPath.section][fromIndexPath.row]
ingredients[toIndexPath.section].insert(dataPiece, atIndex: toIndexPath.row)
ingredients[fromIndexPath.section].removeAtIndex(fromIndexPath.row)
ingredientsTableView.moveRowAtIndexPath(fromIndexPath, toIndexPath: toIndexPath)
ingredientsTableView.reloadData()
}
I wouldn't want to call reloadData, but when not called somehow table indexes got mixed up. Is it necessary? Or there is another way?
Aucun commentaire:
Enregistrer un commentaire