<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITableViewDataSource/tableView(_:commit:forRowAt:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITableViewDataSource(im)tableView:commitEditingStyle:forRowAtIndexPath:"
  },
  "title" : "tableView(_:commit:forRowAt:)"
}
-->

# tableView(_:commit:forRowAt:)

Asks the data source to commit the insertion or deletion of a specified row.

```
optional func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath)
```

## Parameters

`tableView`

The table-view object requesting the insertion or deletion.

`editingStyle`

The cell editing style corresponding to a insertion or deletion requested for the row specified by `indexPath`. Possible editing styles are [`UITableViewCell.EditingStyle.insert`](/documentation/UIKit/UITableViewCell/EditingStyle-swift.enum/insert) or [`UITableViewCell.EditingStyle.delete`](/documentation/UIKit/UITableViewCell/EditingStyle-swift.enum/delete).

`indexPath`

An index path locating the row in `tableView`.

## Discussion

When users tap the insertion (green plus) control or Delete button associated with a [`UITableViewCell`](/documentation/UIKit/UITableViewCell) object in the table view, the table view sends this message to the data source, asking it to commit the change. (If the user taps the deletion (red minus) control, the table view then displays the Delete button to get confirmation.) The data source commits the insertion or deletion by invoking the `UITableView` methods [`insertRows(at:with:)`](/documentation/UIKit/UITableView/insertRows(at:with:)) or [`deleteRows(at:with:)`](/documentation/UIKit/UITableView/deleteRows(at:with:)), as appropriate.

To enable the swipe-to-delete feature of table views (wherein a user swipes horizontally across a row to display a Delete button), you must implement this method.

You shouldn’t call [`setEditing(_:animated:)`](/documentation/UIKit/UITableView/setEditing(_:animated:)) within an implementation of this method. If for some reason you must, invoke it after a delay by using the <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/perform(_:with:afterDelay:)> method.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)