Delegate Reference

Complete reference for all SwiftDataTableDelegate methods.

The SwiftDataTableDelegate protocol provides callbacks for user interactions and customization points. All methods have default implementations, so you only need to implement the ones you care about.

Setting Up

Conform your view controller to SwiftDataTableDelegate and set it as the delegate:

class MyViewController: UIViewController, SwiftDataTableDelegate {
    var dataTable: SwiftDataTable!

    override func viewDidLoad() {
        super.viewDidLoad()
        dataTable = SwiftDataTable(data: items, columns: columns)
        dataTable.delegate = self
        view.addSubview(dataTable)
    }
}

Selection Events

Respond to user taps on rows.

didSelectItem

Called when a user taps a cell. The indexPath.section is the row index, indexPath.item is the column index.

func didSelectItem(_ dataTable: SwiftDataTable, indexPath: IndexPath) {
    let row = indexPath.section
    let column = indexPath.item
    let item = items[row]
    // Handle selection - show detail, present action sheet, etc.
}

didDeselectItem

Called when a previously selected cell is deselected.

func didDeselectItem(_ dataTable: SwiftDataTable, indexPath: IndexPath) {
    // Handle deselection if needed
}

Respond to taps on column headers and footers. Useful for custom sorting UI, filtering, or showing column options.

didTapHeaderAt

Called when a user taps a column header. By default, tapping a header triggers sorting - use this to add custom behavior.

func dataTable(_ dataTable: SwiftDataTable, didTapHeaderAt columnIndex: Int) {
    print("Tapped header for column \(columnIndex)")
    // Show filter options, column settings, etc.
}

didTapFooterAt

Called when a user taps a column footer.

func dataTable(_ dataTable: SwiftDataTable, didTapFooterAt columnIndex: Int) {
    print("Tapped footer for column \(columnIndex)")
}

Row and Column Sizing

Override default sizing on a per-row or per-column basis.

heightForRowAt

Return a custom height for a specific row. Return nil to use the default height from configuration.

func dataTable(_ dataTable: SwiftDataTable, heightForRowAt index: Int) -> CGFloat? {
    // Make the first row taller
    return index == 0 ? 60 : nil
}

widthForColumnAt

Return a custom width for a specific column. Return nil to use the default width calculation.

func dataTable(_ dataTable: SwiftDataTable, widthForColumnAt index: Int) -> CGFloat? {
    // Make the first column wider
    return index == 0 ? 200 : nil
}

Section Heights

Customize the height of various table sections.

MethodDescription
heightForSectionHeader(in:)Height of column headers row
heightForSectionFooter(in:)Height of column footers row
heightForSearchView(in:)Height of the search bar section
heightOfInterRowSpacing(in:)Spacing between rows
func heightForSectionHeader(in dataTable: SwiftDataTable) -> CGFloat? {
    return 50  // Custom header height
}

func heightOfInterRowSpacing(in dataTable: SwiftDataTable) -> CGFloat? {
    return 2  // Add spacing between rows
}

Layout Behavior

Control how elements float, scale, and scroll.

MethodDescriptionDefault
shouldContentWidthScaleToFillFrame(in:)Whether columns expand to fill available widthtrue
shouldSectionHeadersFloat(in:)Keep headers visible while scrollingtrue
shouldSectionFootersFloat(in:)Keep footers visible while scrollingtrue
shouldSearchHeaderFloat(in:)Keep search bar visible while scrollingtrue
shouldShowSearchSection(in:)Show/hide the search sectiontrue
shouldShowVerticalScrollBars(in:)Show vertical scroll indicatorstrue
shouldShowHorizontalScrollBars(in:)Show horizontal scroll indicatorstrue
func shouldSectionHeadersFloat(in dataTable: SwiftDataTable) -> Bool? {
    return false  // Headers scroll with content
}

func shouldShowSearchSection(in dataTable: SwiftDataTable) -> Bool? {
    return false  // Hide search bar
}

Fixed Columns

Pin columns to the left or right edge so they remain visible while scrolling horizontally.

func fixedColumns(for dataTable: SwiftDataTable) -> DataTableFixedColumnType? {
    return DataTableFixedColumnType(leftColumns: 1)  // Pin first column
}

See Fixed Columns for more details on pinning columns.

RTL Support

Enable right-to-left layout for languages like Arabic and Hebrew.

func shouldSupportRightToLeftInterfaceDirection(in dataTable: SwiftDataTable) -> Bool? {
    return true  // Enable RTL support
}

Complete Method Reference

Here's the complete list of all delegate methods:

CategoryMethod
SelectiondidSelectItem(_:indexPath:)
SelectiondidDeselectItem(_:indexPath:)
Header/FooterdataTable(_:didTapHeaderAt:)
Header/FooterdataTable(_:didTapFooterAt:)
SizingdataTable(_:heightForRowAt:)
SizingdataTable(_:widthForColumnAt:)
Section HeightsheightForSectionHeader(in:)
Section HeightsheightForSectionFooter(in:)
Section HeightsheightForSearchView(in:)
Section HeightsheightOfInterRowSpacing(in:)
LayoutshouldContentWidthScaleToFillFrame(in:)
LayoutshouldSectionHeadersFloat(in:)
LayoutshouldSectionFootersFloat(in:)
LayoutshouldSearchHeaderFloat(in:)
LayoutshouldShowSearchSection(in:)
Scroll BarsshouldShowVerticalScrollBars(in:)
Scroll BarsshouldShowHorizontalScrollBars(in:)
Fixed ColumnsfixedColumns(for:)
RTLshouldSupportRightToLeftInterfaceDirection(in:)

All delegate methods return optionals. Return nil to use the default behavior from DataTableConfiguration.