UITableView
extension UITableView
Delegate and DataSource
UITableView closures make it easy to implement UITableViewDelegate and
UITableViewDataSource protocol methods in an organized way. The following
is an example of a simple table view that displays strings in a basic cell.
func loadTableView() {
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
tableView
.numberOfRows { _ in
countries.count
}.cellForRow { indexPath in
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel!.text = countries[indexPath.row]
return cell
}.didSelectRowAt {
print("\(countries[$0.row]) selected")
}.reloadData()
}
Arrays
These operations are common. Usually, they involve populating the UITableView
with the values from an array. Closures framework gives you a convenient
way to pass your array to the table view, so that it can perform the boiler
plate operations for you, especially the ones that are required to make the table
view perform at a basic level.
Important
Please remember that SwiftArrays are value types. This means that they
are copied when mutated. When the values or sequence of your array changes, you will
need to call addElements again, just before you call reloadData().
func loadTableView(countries: [String]) {
tableView
.addElements(countries, cell: UITableViewCell.self) { country, cell, index in
cell.textLabel!.text = country
}.reloadData()
}
Multiple Sections
And finally, you can just as easily have a grouped table view, by binding a 2-dimensional array. Before calling this method, we grouped the countries by their first letter.
func loadTableView(countries: [[String]]) {
tableView.addSections(
countries,
cell: UITableViewCell.self,
headerTitle: { countryArray,index in
String(countryArray.first!.first!)},
row: { country, cell, index in
cell.textLabel!.text = country
})
/**
This also allows you to override any default behavior so
you aren't overly committed, even though you're initially binding everything
to the `Array`.
*/
tableView
.estimatedHeightForHeaderInSection { _ in
30
}.heightForHeaderInSection { _ in
30
}.reloadData()
}
-
This method defaults many of the boilerplate callbacks needed to populate a UITableView when using an
Arrayas a data source. The defaults that this method takes care of:- Registers the cell’s class and reuse identifier with a default value
- Optionally uses a cellNibName value to create the cell from a nib file from the main bundle
- Handles cell dequeueing and provides a reference to the cell
in the
rowclosure for you to modify in place. - Provides the number of sections
- Provides the number of rows
This method simply sets basic default behavior. This means that you can override the default table view handlers after this method is called. However, remember that order matters. If you call this method after you override the
numberOfSectionsIncallback, for instance, the closure you passed intonumberOfSectionsInwill be wiped out by this method and you will have to override that closure handler again.Important
Please remember that SwiftArrays are value types. This means that they are copied when mutaded. When the values or sequence of your array changes, you will need to call this method again, just before you call reloadData(). If you have a lot of table view customization in addtion to a lot of updates to your array, it is more appropriate to use the individual closure handlers instead of this method.
An example of calling this method:
tableView.addElements(<#myArray#>, cell: <#MyUITableViewCellClass#>.self) { element, cell, index in cell.textLabel!.text = <#T##someString(from: element)##String#> }Declaration
Swift
@discardableResult public func addElements<Element,Cell>( _ elements: [Element], cell: Cell.Type, cellNibName: String? = nil, row: @escaping (_ element: Element, _ cell: inout Cell,_ index: Int) -> Void) -> Self where Cell: UITableViewCellParameters
arrayAn Array to be used for each row.
cellA type of cell to use when calling
dequeueReusableCell(withIdentifier:for:)cellNibNameIf non-nil, the cell will be dequeued using a nib with this name from the main bundle
rowA closure that’s called when a cell is about to be shown and needs to be configured.
Return Value
itself so you can daisy chain the other datasource calls
-
This method defaults many of the boilerplate callbacks needed to populate a UITableView when using an
Arrayas a data source. The defaults that this method takes care of:- Registers the cell’s class and reuse identifier with a default value
- Optionally uses a cellNibName value to create the cell from a nib file from the main bundle
- Handles cell dequeueing and provides a reference to the cell
in the
rowclosure for you to modify in place. - Provides the number of sections
- Provides the number of rows
- Calls the headerView handler when each section title view needs to be shown.
This method simply sets basic default behavior. This means that you can override the default table view handlers after this method is called. However, remember that order matters. If you call this method after you override the
numberOfSectionsIncallback, for instance, the closure you passed intonumberOfSectionsInwill be wiped out by this method and you will have to override that closure handler again.Important
Please remember that SwiftArrays are value types. This means that they are copied when mutaded. When the values or sequence of your array changes, you will need to call this method again, just before you call reloadData(). If you have a lot of table view customization in addtion to a lot of updates to your array, it is more appropriate to use the individual closure handlers instead of this method.
An example of calling this method:
tableView.addSections( <#my2dArray#>, cell: <#MyUITableViewCellClass#>.self, headerView: { array, index in <#T##aView(from: array)##UIView#>}, row: { element, cell, index in cell.textLabel!.text = <#T##someString(from: element)##String#>} )Declaration
Swift
@discardableResult public func addSections<Element,Cell>( _ elements: [[Element]], cell: Cell.Type, cellNibName: String? = nil, headerView: @escaping ((_ elements: [Element], _ index: Int) -> UIView), row: @escaping (_ element: Element, _ cell: inout Cell,_ index: Int) -> Void) -> Self where Cell: UITableViewCellParameters
arrayA two dimensional
Arrayto be used for each section.cellA type of cell to use when calling
dequeueReusableCell(withIdentifier:for:)cellNibNameIf non-nil, the cell will be dequeued using a nib with this name from the main bundle
headerViewA closure that provides the information needed to display the section’s header as an instance of
UIView.rowA closure that’s called when a cell is about to be shown and needs to be configured.
Return Value
itself so you can daisy chain the other datasource calls
-
This method defaults many of the boilerplate callbacks needed to populate a UITableView when using an
Arrayas a data source. The defaults that this method takes care of:- Registers the cell’s class and reuse identifier with a default value
- Optionally uses a cellNibName value to create the cell from a nib file from the main bundle
- Handles cell dequeueing and provides a reference to the cell
in the
rowclosure for you to modify in place. - Provides the number of sections
- Provides the number of rows
- Calls the headerView handler when each section title view needs to be shown.
This method simply sets basic default behavior. This means that you can override the default table view handlers after this method is called. However, remember that order matters. If you call this method after you override the
numberOfSectionsIncallback, for instance, the closure you passed intonumberOfSectionsInwill be wiped out by this method and you will have to override that closure handler again.Important
Please remember that SwiftArrays are value types. This means that they are copied when mutaded. When the values or sequence of your array changes, you will need to call this method again, just before you call reloadData(). If you have a lot of table view customization in addtion to a lot of updates to your array, it is more appropriate to use the individual closure handlers instead of this method.
An example of calling this method:
tableView.addSections( <#my2dArray#>, cell: <#MyUITableViewCellClass#>.self, headerTitle: { array, index in <#T##aTitle(from: array)##String#>}, row: { element, cell, index in cell.textLabel!.text = <#T##someString(from: element)##String#>} )Declaration
Swift
@discardableResult public func addSections<Element,Cell>( _ elements: [[Element]], cell: Cell.Type, cellNibName: String? = nil, headerTitle: ((_ elements: [Element], _ index: Int) -> String)? = nil, row: @escaping (_ element: Element, _ cell: inout Cell,_ index: Int) -> Void) -> Self where Cell: UITableViewCellParameters
arrayA two dimensional
Arrayto be used for each section.cellA type of cell to use when calling
dequeueReusableCell(withIdentifier:for:)cellNibNameIf non-nil, the cell will be dequeued using a nib with this name from the main bundle
headerTitleA closure that provides the information needed to display the section’s header as a
String.rowA closure that’s called when a cell is about to be shown and needs to be configured.
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:willDisplay:forRowAt:) method
Declaration
Swift
@discardableResult public func willDisplay(handler: @escaping (_ cell: UITableViewCell, _ forRowAt: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:willDisplayHeaderView:forSection:) method
Declaration
Swift
@discardableResult public func willDisplayHeaderView(handler: @escaping (_ view: UIView, _ forSection: Int) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:willDisplayFooterView:forSection:) method
Declaration
Swift
@discardableResult public func willDisplayFooterView(handler: @escaping (_ view: UIView, _ section: Int) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didEndDisplaying:forRowAt:) method
Declaration
Swift
@discardableResult public func didEndDisplaying(handler: @escaping (_ cell: UITableViewCell, _ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didEndDisplayingHeaderView:forSection:) method
Declaration
Swift
@discardableResult public func didEndDisplayingHeaderView(handler: @escaping (_ view: UIView, _ section: Int) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didEndDisplayingFooterView:forSection:) method
Declaration
Swift
@discardableResult public func didEndDisplayingFooterView(handler: @escaping (_ view: UIView, _ section: Int) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:heightForRowAt:) method
Declaration
Swift
@discardableResult public func heightForRowAt(handler: @escaping (_ indexPath: IndexPath) -> CGFloat) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:heightForHeaderInSection:) method
Declaration
Swift
@discardableResult public func heightForHeaderInSection(handler: @escaping (_ section: Int) -> CGFloat) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:heightForFooterInSection:) method
Declaration
Swift
@discardableResult public func heightForFooterInSection(handler: @escaping (_ section: Int) -> CGFloat) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:estimatedHeightForRowAt:) method
Declaration
Swift
@discardableResult public func estimatedHeightForRowAt(handler: @escaping (_ indexPath: IndexPath) -> CGFloat) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:estimatedHeightForHeaderInSection:) method
Declaration
Swift
@discardableResult public func estimatedHeightForHeaderInSection(handler: @escaping (_ section: Int) -> CGFloat) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:estimatedHeightForFooterInSection:) method
Declaration
Swift
@discardableResult public func estimatedHeightForFooterInSection(handler: @escaping (_ section: Int) -> CGFloat) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:viewForHeaderInSection:) method
Declaration
Swift
@discardableResult public func viewForHeaderInSection(handler: @escaping (_ section: Int) -> UIView?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:viewForFooterInSection:) method
Declaration
Swift
@discardableResult public func viewForFooterInSection(handler: @escaping (_ section: Int) -> UIView?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:accessoryButtonTappedForRowWith:) method
Declaration
Swift
@discardableResult public func accessoryButtonTappedForRowWith(handler: @escaping (_ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:shouldHighlightRowAt:) method
Declaration
Swift
@discardableResult public func shouldHighlightRowAt(handler: @escaping (_ indexPath: IndexPath) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didHighlightRowAt:) method
Declaration
Swift
@discardableResult public func didHighlightRowAt(handler: @escaping (_ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didUnhighlightRowAt:) method
Declaration
Swift
@discardableResult public func didUnhighlightRowAt(handler: @escaping (_ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:willSelectRowAt:) method
Declaration
Swift
@discardableResult public func willSelectRowAt(handler: @escaping (_ indexPath: IndexPath) -> IndexPath?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:willDeselectRowAt:) method
Declaration
Swift
@discardableResult public func willDeselectRowAt(handler: @escaping (_ indexPath: IndexPath) -> IndexPath?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didSelectRowAt:) method
Declaration
Swift
@discardableResult public func didSelectRowAt(handler: @escaping (_ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didDeselectRowAt:) method
Declaration
Swift
@discardableResult public func didDeselectRowAt(handler: @escaping (_ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:editingStyleForRowAt:) method
Declaration
Swift
@discardableResult public func editingStyleForRowAt(handler: @escaping (_ indexPath: IndexPath) -> UITableViewCell.EditingStyle) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:titleForDeleteConfirmationButtonForRowAt:) method
Declaration
Swift
@discardableResult public func titleForDeleteConfirmationButtonForRowAt(handler: @escaping (_ indexPath: IndexPath) -> String?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:editActionsForRowAt:) method
Declaration
Swift
@available(iOS, deprecated: 13.0) @discardableResult public func editActionsForRowAt(handler: @escaping (_ indexPath: IndexPath) -> [UITableViewRowAction]?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:shouldIndentWhileEditingRowAt:) method
Declaration
Swift
@discardableResult public func shouldIndentWhileEditingRowAt(handler: @escaping (_ indexPath: IndexPath) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:willBeginEditingRowAt:) method
Declaration
Swift
@discardableResult public func willBeginEditingRowAt(handler: @escaping (_ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didEndEditingRowAt:) method
Declaration
Swift
@discardableResult public func didEndEditingRowAt(handler: @escaping (_ indexPath: IndexPath?) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:targetIndexPathForMoveFromRowAt:toProposedIndexPath:) method
Declaration
Swift
@discardableResult public func targetIndexPathForMoveFromRowAt(handler: @escaping (_ sourceIndexPath: IndexPath, _ proposedDestinationIndexPath: IndexPath) -> IndexPath) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:indentationLevelForRowAt:) method
Declaration
Swift
@discardableResult public func indentationLevelForRowAt(handler: @escaping (_ indexPath: IndexPath) -> Int) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:shouldShowMenuForRowAt:) method
Declaration
Swift
@available(iOS, deprecated: 13.0) @discardableResult public func shouldShowMenuForRowAt(handler: @escaping (_ indexPath: IndexPath) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:canPerformAction:forRowAt:withSender:) method
Declaration
Swift
@available(iOS, deprecated: 13.0) @discardableResult public func canPerformAction(handler: @escaping (_ action: Selector, _ indexPath: IndexPath, _ sender: Any?) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:performAction:forRowAt:withSender:) method
Declaration
Swift
@available(iOS, deprecated: 13.0) @discardableResult public func performAction(handler: @escaping (_ action: Selector, _ indexPath: IndexPath, _ sender: Any?) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:canFocusRowAt:) method
Declaration
Swift
@discardableResult public func canFocusRowAt(handler: @escaping (_ indexPath: IndexPath) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:shouldUpdateFocusIn:) method
Declaration
Swift
@discardableResult public func shouldUpdateFocus(handler: @escaping (_ context: UITableViewFocusUpdateContext) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didUpdateFocusIn:with:) method
Declaration
Swift
@discardableResult public func didUpdateFocus(handler: @escaping (_ context: UITableViewFocusUpdateContext, _ coordinator: UIFocusAnimationCoordinator) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s indexPathForPreferredFocusedView(in:) method
Declaration
Swift
@discardableResult public func indexPathForPreferredFocusedView(handler: @escaping () -> IndexPath?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:numberOfRowsInSection:) method
Declaration
Swift
@discardableResult public func numberOfRows(handler: @escaping (_ section: Int) -> Int) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:cellForRowAt:) method
Declaration
Swift
@discardableResult public func cellForRow(handler: @escaping (_ indexPath: IndexPath) -> UITableViewCell) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s numberOfSections(in:) method
Declaration
Swift
@discardableResult public func numberOfSectionsIn(handler: @escaping () -> Int) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:titleForHeaderInSection:) method
Declaration
Swift
@discardableResult public func titleForHeaderInSection(handler: @escaping (_ section: Int) -> String?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:titleForFooterInSection:) method
Declaration
Swift
@discardableResult public func titleForFooterInSection(handler: @escaping (_ section: Int) -> String?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:canEditRowAt:) method
Declaration
Swift
@discardableResult public func canEditRowAt(handler: @escaping (_ indexPath: IndexPath) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:canMoveRowAt:) method
Declaration
Swift
@discardableResult public func canMoveRowAt(handler: @escaping (_ indexPath: IndexPath) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s sectionIndexTitles(for:) method
Declaration
Swift
@discardableResult public func sectionIndexTitles(handler: @escaping () -> [String]?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:sectionForSectionIndexTitle:at:) method
Declaration
Swift
@discardableResult public func sectionForSectionIndexTitle(handler: @escaping (_ title: String, _ index: Int) -> Int) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:commit:forRowAt:) method
Declaration
Swift
@discardableResult public func commit(handler: @escaping (_ editingStyle: UITableViewCell.EditingStyle, _ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDataSource’s tableView(_:moveRowAt:to:) method
Declaration
Swift
@discardableResult public func moveRowAt(handler: @escaping (_ sourceIndexPath: IndexPath, _ destinationIndexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent datasource method
Return Value
itself so you can daisy chain the other datasource calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:leadingSwipeActionsConfigurationForRowAt:) method
Declaration
Swift
@available(iOS 11, *) @discardableResult public func leadingSwipeActionsConfigurationForRowAt(handler: @escaping (_ indexPath: IndexPath) -> UISwipeActionsConfiguration?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:trailingSwipeActionsConfigurationForRowAt:) method
Declaration
Swift
@available(iOS 11, *) @discardableResult public func trailingSwipeActionsConfigurationForRowAt(handler: @escaping (_ indexPath: IndexPath) -> UISwipeActionsConfiguration?) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:shouldSpringLoadRowAt:) method
Declaration
Swift
@available(iOS 11, *) @discardableResult public func shouldSpringLoadRowAt(handler: @escaping (_ indexPath: IndexPath, _ context: UISpringLoadedInteractionContext) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:shouldBeginMultipleSelectionInteractionAt:) method
Declaration
Swift
@available(iOS 13, *) @discardableResult public func shouldBeginMultipleSelectionInteraction(handler: @escaping (_ indexPath: IndexPath) -> Bool) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableView(_:didBeginMultipleSelectionInteractionAt:) method
Declaration
Swift
@available(iOS 13, *) @discardableResult public func didBeginMultipleSelectionInteractionAt(handler: @escaping (_ indexPath: IndexPath) -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Equivalent to implementing UITableViewDelegate’s tableViewDidEndMultipleSelectionInteraction(_:) method
Declaration
Swift
@available(iOS 13, *) @discardableResult public func didEndMultipleSelectionInteraction(handler: @escaping () -> Void) -> SelfParameters
handlerThe closure that will be called in place of its equivalent delegate method
Return Value
itself so you can daisy chain the other delegate calls
-
Clears any delegate/dataSource closures that were assigned to this
UITableView. This cleans up memory as well as sets the delegate/dataSource properties to nil. This is typically only used for explicit cleanup. You are not required to call this method.Declaration
Swift
@objc override public func clearClosureDelegates()
View on GitHub
UITableView Extension Reference