Rawan Rawan - 2 months ago 8
iOS Question

how to delete a cell from a UITableView with multi section in swift

i'm trying to delete a cell from UITableView in swift, i follow this tutorial: http://www.ioscreator.com/tutorials/delete-rows-table-view-ios8-swift
the problem is my UITableView has many section, so i can't delete the cell the way like the tutorial.
any one know how to delete cell form table with multiple section?


You cannot delete multiple cells at once with the method described in the tutorial. That will only work for single cell. If you select multiple cells and use button, for example, to trigger delete action, your code could look something like this:

if let indexPaths = tableView.indexPathsForSelectedRows() as? [NSIndexPath] {
    for indexPath in indexPaths {
        // one by one remove items from your datasource

    tableView.deleteRowsAtIndexPaths(indexPaths, withRowAnimation: .Automatic)