override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
machine.formulas.remove(at: indexPath.row)
machine.saveFormulas()
tableView.deleteRows(at: [indexPath], with: .fade)
self.perform(#selector(reloadTable), with: nil, afterDelay: 2)
}
}
@objc func reloadTable() {
DispatchQueue.main.async { //please do all interface updates in main thread only
self.tableView.reloadData()
}
}
As of Xcode 6.1.1, there are some tiny changes to Dash's answer.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
// handle delete (by removing the data from your array and updating the tableview)
}
}