<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "tvOS: -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITableViewDataSource",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITableViewDataSource"
  },
  "title" : "UITableViewDataSource"
}
-->

# UITableViewDataSource

The methods that an object adopts to manage data and provide cells for a table view.

```
@MainActor protocol UITableViewDataSource : NSObjectProtocol
```

## Overview

Table views manage only the presentation of their data; they don’t manage the data itself. To manage the data, you provide the table with a data source object — an object that implements the [`UITableViewDataSource`](/documentation/UIKit/UITableViewDataSource) protocol. A data source object responds to data-related requests from the table. It also manages the table’s data directly, or coordinates with other parts of your app to manage that data. Other responsibilities of the data source object include:

- Reporting the number of sections and rows in the table.
- Providing cells for each row of the table.
- Providing titles for section headers and footers.
- Configuring the table’s index, if any.
- Responding to user- or table-initiated updates that require changes to the underlying data.

Only two methods of this protocol are required, and they’re shown in the following example code.

```swift
// Return the number of rows for the table.     
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
   return 0
}

// Provide a cell object for each row.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
   // Fetch a cell of the appropriate type.
   let cell = tableView.dequeueReusableCell(withIdentifier: "cellTypeIdentifier", for: indexPath)
   
   // Configure the cell’s contents.
   cell.textLabel!.text = "Cell text"
       
   return cell
}
```

Use other methods of this protocol to enable specific features for your table. For example, you must implement the [`tableView(_:commit:forRowAt:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:commit:forRowAt:)) method to enable the swipe-to-delete feature for rows.

For information about how to create and configure your table’s cells using your data source object, see [Filling a table with data](/documentation/UIKit/filling-a-table-with-data).

### Specify the location of rows and sections

Table views communicate the location of cells to you using the <doc://com.apple.documentation/documentation/Foundation/NSIndexPath/row> and <doc://com.apple.documentation/documentation/Foundation/NSIndexPath/section> properties of <doc://com.apple.documentation/documentation/Foundation/NSIndexPath> objects. Row and section indexes are zero based, so the first section is at index `0`, the second at index `1`, and so on. Similarly, the first row of each section is at index `0`, which means you need both the <doc://com.apple.documentation/documentation/Foundation/NSIndexPath/section> and <doc://com.apple.documentation/documentation/Foundation/NSIndexPath/row> values to identify a row uniquely. If your table has no sections, you need only the <doc://com.apple.documentation/documentation/Foundation/NSIndexPath/row> value.

![Illustration that shows a table with multiple sections. The first section has an index of 0 and no row value. The nine rows in the first section have indexes between 0 and 8. The second section has an index of 1 and no row value. Its first row starts at index 0 again.](images/com.apple.uikit/media-3148902@2x.png)

## Topics

### Providing the number of rows and sections

[`tableView(_:numberOfRowsInSection:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:numberOfRowsInSection:))

Tells the data source to return the number of rows in a given section of a table view.

[`numberOfSections(in:)`](/documentation/UIKit/UITableViewDataSource/numberOfSections(in:))

Asks the data source to return the number of sections in the table view.

### Providing cells, headers, and footers

[`tableView(_:cellForRowAt:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:cellForRowAt:))

Asks the data source for a cell to insert in a particular location of the table view.

[`tableView(_:titleForHeaderInSection:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:titleForHeaderInSection:))

Asks the data source for the title of the header of the specified section of the table view.

[`tableView(_:titleForFooterInSection:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:titleForFooterInSection:))

Asks the data source for the title of the footer of the specified section of the table view.

### Inserting or deleting table rows

[`tableView(_:commit:forRowAt:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:commit:forRowAt:))

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

[`tableView(_:canEditRowAt:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:canEditRowAt:))

Asks the data source to verify that the given row is editable.

### Reordering table rows

[`tableView(_:canMoveRowAt:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:canMoveRowAt:))

Asks the data source whether a given row can move to another location in the table view.

[`tableView(_:moveRowAt:to:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:moveRowAt:to:))

Tells the data source to move a row at a specific location in the table view to another location.

### Configuring an index

[`sectionIndexTitles(for:)`](/documentation/UIKit/UITableViewDataSource/sectionIndexTitles(for:))

Asks the data source to return the titles for the sections of a table view.

[`tableView(_:sectionForSectionIndexTitle:at:)`](/documentation/UIKit/UITableViewDataSource/tableView(_:sectionForSectionIndexTitle:at:))

Asks the data source to return the index of the section having the given title and section title index.



---

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)