I want the user to be able to reorder the table, as well as delete rows by scrolling, but I do not want the delete button to always be visible.
To enable re-ordering, I obviously turned on the edit processing method, etc:
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
tableView.beginUpdates()
deleteItemAtRow(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
tableView.endUpdates()
}
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
moveItemFromIndex(sourceIndexPath.row, toIndex: destinationIndexPath.row)
}
but I also had to insert
self.editing = true
in viewDidLoad. However, this makes the small round delete button visible all the time (I just want to use swipe to remove functionality). I can get rid of the little round button with
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.None
}
but it also stops the user deleting with a swipe.
, : ( "", ), , ?