List Controller Editing Modes

General

One of the properties of ListViewController is "editingStyle". This property defines the style in which the ListShould look like when it will enter the editing mode. To provide apropiate "editingStyle" one should cerate an class conforming to the protocol "GSDListViewMultiselectionConfiguration". The default configurations are:

  • GSDListViewDeleteConfiguration - the configuration which will allow the user to delete items from the list
  • GSDListViewMoveRowsConfiguration - the configuration which will alow the user to move elements inside the list, and reorder them
  • GSDListViewMultiselectionConfiguration - the configuration which will allow the user to select many elements in the list

Custom actions

"GSDListViewMultiselectionConfiguration" can be also used to provide the configuration for actions showed on swipe in cell. Sample implementation is showed below:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class MyEditingStyle: GSDListViewEditingConfiguration {
    var editingStyle:UITableViewCellEditingStyle? = UITableViewCellEditingStyle.delete
    var enablesMultiselection:Bool  = false

    func commitEditingStyle(_ tableView: UITableView, indexPath: IndexPath, dataSource:GSDListViewDataSource? ){ }
    func moveRowAt( sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath, dataSource:GSDListViewDataSource?){}
    func canMoveRowAtIndex(indexPath:IndexPath, dataSource:GSDListViewDataSource?)->Bool { return false }
    func editActionsForRowAt (indexPath: IndexPath, dataSource:GSDListViewDataSource?) -> [UITableViewRowAction]?{ return self.createSampleTableViewEditingActions() }


    func createSampleTableViewEditingActions()->[UITableViewRowAction] {
        var tempActions:[UITableViewRowAction] = []
        let tempAction = UITableViewRowAction(style: UITableViewRowActionStyle.normal, title: "Clear"){ (rowAction, indexPath) in
            print("DID CLEAR ON INDEX \(indexPath)")
        }
        tempAction.backgroundColor = UIColor.green
        tempActions.append(tempAction)
        return tempActions
    }
}