Protocol: UITableViewDataSource
Overview
The UITableViewDataSource protocol is adopted by an object that mediates the application’s data model for a UITableView object. The data source provides the table-view object with the information it needs to construct and modify a table view. Asks the data source to return the number of sections in the table view.Asks the data source to return the titles for the sections for a table view.Asks the data source to verify that the given row is editable.Asks the data source whether a given row can be moved to another location in the table view.Asks the data source for a cell to insert in a particular location of the table view. (required)Asks the data source to commit the insertion or deletion of a specified row in the receiver.Tells the data source to move a row at a specific location in the table view to another location.Tells the data source to return the number of rows in a given section of a table view. (required)Asks the data source to return the index of the section having the given title and section title index.Asks the data source for the title of the footer of the specified section of the table view.Asks the data source for the title of the header of the specified section of the table view.
Instance Method Summary (collapse)
-
- numberOfSectionsInTableView:
Asks the data source to return the number of sections in the table view.
-
- sectionIndexTitlesForTableView:
Asks the data source to return the titles for the sections for a table view.
-
- tableView:canEditRowAtIndexPath:
Asks the data source to verify that the given row is editable.
-
- tableView:canMoveRowAtIndexPath:
Asks the data source whether a given row can be moved to another location in the table view.
-
- tableView:cellForRowAtIndexPath:
Asks the data source for a cell to insert in a particular location of the table view.
-
- tableView:commitEditingStyle:forRowAtIndexPath:
Asks the data source to commit the insertion or deletion of a specified row in the receiver.
-
- tableView:moveRowAtIndexPath:toIndexPath:
Tells the data source to move a row at a specific location in the table view to another location.
-
- tableView:numberOfRowsInSection:
Tells the data source to return the number of rows in a given section of a table view.
-
- tableView:sectionForSectionIndexTitle:atIndex:
Asks the data source to return the index of the section having the given title and section title index.
-
- tableView:titleForFooterInSection:
Asks the data source for the title of the footer of the specified section of the table view.
-
- tableView:titleForHeaderInSection:
Asks the data source for the title of the header of the specified section of the table view.
Instance Method Details
- (Integer) numberOfSectionsInTableView(tableView)
Asks the data source to return the number of sections in the table view.
- (Array) sectionIndexTitlesForTableView(tableView)
Asks the data source to return the titles for the sections for a table view.
- (Boolean) tableView(tableView, canEditRowAtIndexPath:indexPath)
Asks the data source to verify that the given row is editable. The method permits the delegate to exclude individual rows from being treated as editable. Editable rows display the insertion or deletion control in their cells. If this method is not implemented, all rows are assumed to be editable. Rows that are not editable ignore the editingStyle property of a UITableViewCell object and do no indentation for the deletion or insertion control. Rows that are editable, but that do not want to have an insertion or remove control shown, can return UITableViewCellEditingStyleNone from the tableView:editingStyleForRowAtIndexPath: delegate method.
- (Boolean) tableView(tableView, canMoveRowAtIndexPath:indexPath)
Asks the data source whether a given row can be moved to another location in the table view. This method allows the delegate to specify that the reordering control for a the specified row not be shown. By default, the reordering control is shown if the data source implements the tableView:moveRowAtIndexPath:toIndexPath: method.
- (UITableViewCell) tableView(tableView, cellForRowAtIndexPath:indexPath)
Asks the data source for a cell to insert in a particular location of the table view. (required) The returned UITableViewCell object is frequently one that the application reuses for performance reasons. You should fetch a previously created cell object that is marked for reuse by sending a dequeueReusableCellWithIdentifier: message to tableView. The identifier for a reusable cell object is assigned when the delegate initializes the cell object by calling the initWithStyle:reuseIdentifier: method of UITableViewCell. Various attributes of a table cell are set automatically based on whether the cell is a separator and on information the data source provides, such as for accessory views and editing controls.
- (Object) tableView(tableView, commitEditingStyle:editingStyle, forRowAtIndexPath:indexPath)
Asks the data source to commit the insertion or deletion of a specified row in the receiver. When users tap the insertion (green plus) control or Delete button associated with a 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 insertRowsAtIndexPaths:withRowAnimation: or deleteRowsAtIndexPaths:withRowAnimation:, 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 should not call setEditing:animated: within an implementation of this method. If for some reason you must, invoke it after a delay by using the performSelector:withObject:afterDelay: method.
- (Object) tableView(tableView, moveRowAtIndexPath:fromIndexPath, toIndexPath:toIndexPath)
Tells the data source to move a row at a specific location in the table view to another location. The UITableView object sends this message to the data source when the user presses the reorder control in fromRow.
- (Integer) tableView(tableView, numberOfRowsInSection:section)
Tells the data source to return the number of rows in a given section of a table view. (required)
- (Integer) tableView(tableView, sectionForSectionIndexTitle:title, atIndex:index)
Asks the data source to return the index of the section having the given title and section title index. This method is passed the index number and title of an entry in the section index list and should return the index of the referenced section. To be clear, there are two index numbers in play here: an index to an section index title in the array returned by sectionIndexTitlesForTableView:, and an index to a section of the table view; the former is passed in, and the latter is returned. You implement this method only for table views with a section index list—which can only be table views created in the plain style (UITableViewStylePlain). Note that the array of section titles returned by sectionIndexTitlesForTableView: can have fewer items than the actual number of sections in the table view.
- (String) tableView(tableView, titleForFooterInSection:section)
Asks the data source for the title of the footer of the specified section of the table view. The table view uses a fixed font style for section footer titles. If you want a different font style, return a custom view (for example, a UILabel object) in the delegate method tableView:viewForFooterInSection: instead.
- (String) tableView(tableView, titleForHeaderInSection:section)
Asks the data source for the title of the header of the specified section of the table view. The table view uses a fixed font style for section header titles. If you want a different font style, return a custom view (for example, a UILabel object) in the delegate method tableView:viewForHeaderInSection: instead.