I have my array:
self.colorNames = [[NSArray alloc]
initWithObjects:@\"Red\", @\"Green\",
@\"Blue\", @\"Indigo\", @\"Violet\", nil];
I\'ve
Swift 3 and Swift 4 answer without using reloadData
I prefer using deleteRows instead of using reloadData.
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Enables editing only for the selected table view, if you have multiple table views
return tableView == yourTableView
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Deleting new item in the table
yourTableView.beginUpdates()
yourDataArray.remove(at: indexPath.row)
yourTableView.deleteRows(at: [indexPath], with: .automatic)
yourTableView.endUpdates()
}
}