File tree Expand file tree Collapse file tree
ALTableViewSwift/ALTableView/ALTableView/ALTableViewClasses/ALTableView Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,15 +19,24 @@ public class ALTableView: NSObject {
1919
2020 internal var sectionElements : Array < ALSectionElement >
2121 public weak var delegate : ALTableViewProtocol ?
22+ public weak var editingDelegate : ALTableViewRowEditingProtocol ?
2223 public weak var viewController : UIViewController ?
2324 public weak var tableView : UITableView ?
25+ public var editingAllowed : Bool
26+ public var movingRowsAllowed : Bool
2427
2528
2629 //MARK: - Initializers
2730
28- public init ( sectionElements : Array < ALSectionElement > , viewController : UIViewController , tableView : UITableView ) {
31+ public init ( sectionElements : Array < ALSectionElement > ,
32+ viewController : UIViewController ,
33+ tableView : UITableView ,
34+ editingAllowed : Bool = false ,
35+ movingRowsAllowed : Bool = false ) {
2936
3037 self . sectionElements = sectionElements
38+ self . editingAllowed = editingAllowed
39+ self . movingRowsAllowed = movingRowsAllowed
3140 super . init ( )
3241 self . viewController = viewController
3342 tableView . delegate = self
Original file line number Diff line number Diff line change 88
99import UIKit
1010
11+ public protocol ALTableViewRowEditingProtocol : class {
12+ func rowMoved ( from sourceIndexPath : IndexPath , to destinationIndexPath : IndexPath )
13+ func rowDeleted ( indexPath : IndexPath )
14+ }
15+
1116extension ALTableView {
1217
1318 public func tableView ( _ tableView : UITableView , canMoveRowAt indexPath : IndexPath ) -> Bool {
1419
15- return true
20+ return movingRowsAllowed
1621 }
1722
1823 public func tableView ( _ tableView : UITableView , moveRowAt sourceIndexPath : IndexPath , to destinationIndexPath : IndexPath ) {
@@ -23,19 +28,23 @@ extension ALTableView {
2328 if let originRowElement = originSection ? . getRowElementAt ( index : sourceIndexPath . row ) {
2429 originSection ? . deleteRowElements ( numberOfRowElements : 1 , at : . middle ( sourceIndexPath . row ) )
2530 destinationSection ? . insert ( rowElements : [ originRowElement ] , at : . middle ( destinationIndexPath . row ) )
31+ editingDelegate ? . rowMoved ( from : sourceIndexPath , to : destinationIndexPath )
2632 }
2733 }
2834
2935 public func tableView ( _ tableView : UITableView , canEditRowAt indexPath : IndexPath ) -> Bool {
3036
31- return true
37+ return editingAllowed
3238 }
3339
3440 public func tableView ( _ tableView : UITableView , commit editingStyle : UITableViewCellEditingStyle , forRowAt indexPath : IndexPath ) {
3541
3642 switch editingStyle {
3743 case . delete :
38- self . remove ( at : indexPath , animation : . automatic )
44+ if self . remove ( at : indexPath , animation : . automatic ) {
45+ editingDelegate ? . rowDeleted ( indexPath : indexPath )
46+ }
47+
3948 default :
4049 break
4150 }
You can’t perform that action at this time.
0 commit comments