How i can disable drag interaction on specific sections or cells if
tableView.dragInteractionEnabled = true ?
Now all table cells draggable, but i want to drag specific rows in this table. Is it possible?
How i can disable drag interaction on specific sections or cells if
tableView.dragInteractionEnabled = true ?
Now all table cells draggable, but i want to drag specific rows in this table. Is it possible?
On
You could do it by returning an empty array in tableView(_:itemsForBeginning:at:)
Return value
An array of UIDragItem objects representing the contents of the specified row. Return an empty array if you do not want the user to drag the specified row.
https://developer.apple.com/documentation/uikit/uitableviewdragdelegate/2897492-tableview
In my case (it's a collection view, but approach is the same) I check type of the cell and allow/forbid dragging depending on it:
func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
if let cell = collectionView.cellForItem(at: indexPath) as? CalendarCollectionCell {
let item = cell.calendar!
let itemProvider = NSItemProvider(object: item.name! as NSString)
let dragItem = UIDragItem(itemProvider: itemProvider)
dragItem.localObject = item
return [dragItem]
} else {
return [UIDragItem]()
}
}
Yes, this is possible. First, you need to define which cells are draggable.
In your tableView(cellForRowAt...) method set up a conditional check of some sort.