Rawan Rawan - 1 year ago 109
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?

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download