@@ -14,6 +14,11 @@ import UIKit
14
14
@objc
15
15
public protocol LPRTableViewDelegate : NSObjectProtocol {
16
16
17
+ /// Asks the delegate whether a given row can be moved to another location in the table view based on the gesture location.
18
+ ///
19
+ /// The default is `true`.
20
+ @objc optional func tableView( _ tableView: UITableView , shouldMoveRowAtIndexPath indexPath: IndexPath , forDraggingGesture gesture: UILongPressGestureRecognizer ) -> Bool
21
+
17
22
/// Provides the delegate a chance to modify the cell visually before dragging occurs.
18
23
///
19
24
/// Defaults to using the cell as-is if not implemented.
@@ -107,6 +112,7 @@ extension LPRTableView: UIGestureRecognizerDelegate {
107
112
return ( rows > 0 )
108
113
&& ( indexPath != nil )
109
114
&& canMoveRowAt ( indexPath: indexPath!)
115
+ && shouldMoveRowAt ( indexPath: indexPath!, forDraggingGesture: longPressGestureRecognizer)
110
116
}
111
117
112
118
}
@@ -117,6 +123,10 @@ extension LPRTableView {
117
123
return dataSource? . tableView ? ( self , canMoveRowAt: indexPath) ?? true
118
124
}
119
125
126
+ fileprivate func shouldMoveRowAt( indexPath: IndexPath , forDraggingGesture gesture: UILongPressGestureRecognizer ) -> Bool {
127
+ return longPressReorderDelegate? . tableView ? ( self , shouldMoveRowAtIndexPath: indexPath, forDraggingGesture: longPressGestureRecognizer) ?? true
128
+ }
129
+
120
130
@objc internal func _longPress( _ gesture: UILongPressGestureRecognizer ) {
121
131
let location : CGPoint = gesture. location ( in: self )
122
132
let indexPath : IndexPath ? = indexPathForRow ( at: location)
@@ -410,6 +420,13 @@ open class LPRTableViewController: UITableViewController, LPRTableViewDelegate {
410
420
tableView. register ( UITableViewCell . self, forCellReuseIdentifier: " Cell " )
411
421
}
412
422
423
+ /// Asks the delegate whether a given row can be moved to another location in the table view based on the gesture location.
424
+ ///
425
+ /// The default is `true`. The default implementation of this method is empty—no need to call `super`.
426
+ open func tableView( _ tableView: UITableView , shouldMoveRowAtIndexPath indexPath: IndexPath , forDraggingGesture gesture: UILongPressGestureRecognizer ) -> Bool {
427
+ return true
428
+ }
429
+
413
430
/// Provides the delegate a chance to modify the cell visually before dragging occurs.
414
431
///
415
432
/// Defaults to using the cell as-is if not implemented. The default implementation of this method is empty—no need to call `super`.
0 commit comments