Skip to content

Instantly share code, notes, and snippets.

@aqubi
Created May 31, 2020 05:59
Show Gist options
  • Save aqubi/13012c3eacc9804b2524decbf70f6f2b to your computer and use it in GitHub Desktop.
Save aqubi/13012c3eacc9804b2524decbf70f6f2b to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
if sourceIndexPath.section != destinationIndexPath.section { return }
SURDataManager.shared.move(from: sourceIndexPath, to: destinationIndexPath)
}
func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {
if sourceIndexPath.section != proposedDestinationIndexPath.section {
var row:Int = 0
if sourceIndexPath.section < proposedDestinationIndexPath.section {
row = tableView.numberOfRows(inSection: sourceIndexPath.section) - 1
}
return IndexPath(row: row, section: sourceIndexPath.section)
}
return proposedDestinationIndexPath
}
//MARK:- UITableViewDragDelegate implements
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
return []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment