On iOS 11 it's very easy to move one UITableView row to another index path with drag and drop. But I couldn't find a way to move multiple rows with drag and drop. I've implemented all required delegate methods but UITableView view still doesn't opens up a gap for a multiple-row drop and tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) is never called.
Here is my implementation of UITableViewDropDelegate and UITableViewDragDelegate.
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let itemProvider = NSItemProvider(item: nil, typeIdentifier: nil)
let dragItem = UIDragItem(itemProvider: itemProvider)
return [dragItem]
}
func tableView(_ tableView: UITableView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] {
let itemProvider = NSItemProvider(item: nil, typeIdentifier: nil)
let dragItem = UIDragItem(itemProvider: itemProvider)
return [dragItem]
}
func tableView(_ tableView: UITableView, canHandle session: UIDropSession) -> Bool {
return true
}
func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {
...
}
Drag and drop is enabled and the delegates are set as well.
tableView.dragDelegate = self
tableView.dropDelegate = self
tableView.dragInteractionEnabled = true