Merge pull request #81 from oxview/master
added: canDelete, editingStyle
This commit is contained in:
commit
dd8e5d0625
|
|
@ -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,30 @@ 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
|
||||
}
|
||||
|
||||
public func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
public func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {
|
||||
return invoke(action: .canMoveTo, cell: tableView.cellForRow(at: sourceIndexPath), indexPath: sourceIndexPath, userInfo: [TableKitUserInfoKeys.CellCanMoveProposedIndexPath: proposedDestinationIndexPath]) as? IndexPath ?? proposedDestinationIndexPath
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ struct TableKitNotifications {
|
|||
|
||||
public struct TableKitUserInfoKeys {
|
||||
public static let CellMoveDestinationIndexPath = "TableKitCellMoveDestinationIndexPath"
|
||||
public static let CellCanMoveProposedIndexPath = "CellCanMoveProposedIndexPath"
|
||||
}
|
||||
|
||||
public protocol RowConfigurable {
|
||||
|
|
@ -74,7 +75,9 @@ public enum TableRowActionType {
|
|||
case height
|
||||
case canEdit
|
||||
case configure
|
||||
case canDelete
|
||||
case canMove
|
||||
case canMoveTo
|
||||
case move
|
||||
case custom(String)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue