From cc02531b27ce26bad9842f28a39839b7c1a500e2 Mon Sep 17 00:00:00 2001 From: into Date: Tue, 8 May 2018 13:24:52 +0200 Subject: [PATCH] added: canDelete, editingStyle --- Sources/TableDirector.swift | 14 ++++++++++---- Sources/TableKit.swift | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 548eafb..9088f45 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -257,7 +257,6 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { // MARK: UITableViewDelegate - actions open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let cell = tableView.cellForRow(at: indexPath) if invoke(action: .click, cell: cell, indexPath: indexPath) != nil { @@ -284,10 +283,10 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { } open func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { - if hasAction(.willSelect, atIndexPath: indexPath) { return invoke(action: .willSelect, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? IndexPath } + return indexPath } @@ -300,15 +299,22 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return sections[indexPath.section].rows[indexPath.row].editingActions } - open func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + open func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { + if invoke(action: .canDelete, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? Bool ?? false { + return UITableViewCellEditingStyle.delete + } + return UITableViewCellEditingStyle.none + } + + open func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { invoke(action: .clickDelete, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) } } open func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { - return invoke(action: .canMove, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? Bool ?? true + return invoke(action: .canMove, cell: tableView.cellForRow(at: indexPath), indexPath: indexPath) as? Bool ?? false } open func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) { diff --git a/Sources/TableKit.swift b/Sources/TableKit.swift index c2b10c9..f5f17ef 100644 --- a/Sources/TableKit.swift +++ b/Sources/TableKit.swift @@ -74,6 +74,7 @@ public enum TableRowActionType { case height case canEdit case configure + case canDelete case canMove case move case custom(String)