This is the work I did, but she did the job.
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == UITableViewCellEditingStyle.delete { if itemDetailDict.count - 1 <= 0 { self.mainTable.beginUpdates() let cellOne = self.mainTable.cellForRow(at: indexPath) cellOne?.textLabel?.text = "There are no items." self.mainTable.reloadRows(at: [indexPath], with: .automatic) self.mainTable.endUpdates() } else { self.mainTable.beginUpdates() let removeKey = Array(itemDetailDict.keys)[indexPath.row] itemDetailDict.removeValue(forKey: removeKey) mainTable.deleteRows(at: [indexPath], with: .automatic) self.mainTable.endUpdates() } } }
Essentially in the delete row function, I wanted the user to be able to delete the row, but when there was only one row left, I wanted to show the default message in the table cell.
To do this, I updated the data source, and when there was no more data in the dictionary, I updated the cell to display the text, reloaded the cell, and then called endUpdating in my table view.
Hope this helps.
source share