TableViewDriver

@objc
open class TableViewDriver : NSObject

A data source that drives the table views appereance and behavior based on an underlying TableViewModel.

  • Communicates information for refreshing the table view.

    See more

    Declaration

    Swift

    public enum TableRefreshContext
  • The table view to which the TableViewModel is rendered.

    Declaration

    Swift

    public let tableView: UITableView
  • Describes the current UI state of the table view.

    When this property is set, the UI of the related UITableView will be updated. If not only the content of individual cells/sections has changed, but instead cells/sections were moved/inserted/deleted, the behavior of this setter depends on the value of the automaticDiffingEnabled property.

    If automaticDiffingEnabled is set to true, and cells/sections have been moved/inserted/deleted, updating this property will result in the UI of the table view being updated automatically.

    If automaticDiffingEnabled is set to false, and cells/sections have been moved/inserted/deleted, the caller must update the UITableView state manually, to bring it back in sync with the new model, e.g. by calling reloadData() on the table view.

    Declaration

    Swift

    public var tableViewModel: TableViewModel? { get set }
  • The animation for row insertions.

    Declaration

    Swift

    public var insertionAnimation: UITableView.RowAnimation
  • The animation for row deletions.

    Declaration

    Swift

    public var deletionAnimation: UITableView.RowAnimation
  • Initializes a data source that drives a UITableView based on a TableViewModel.

    Declaration

    Swift

    public init(
        tableView: UITableView,
        tableViewModel: TableViewModel? = nil,
        shouldDeselectUponSelection: Bool = true,
        automaticDiffingEnabled: Bool = true)

    Parameters

    tableView

    the table view to which this data source will render its view models.

    tableViewModel

    the view model that describes the initial state of this table view.

    shouldDeselectUponSelection

    indicates if selected cells should immediately be deselected. Defaults to true.

    automaticDiffingEnabled

    defines whether or not this data source updates the table view automatically when cells/sections are moved/inserted/deleted. Defaults to true.

  • Updates all currently visible cells and sections, such that they reflect the latest state decribed in their respective view models. Typically this method should not be called directly, as it is called automatically whenever the tableViewModel property is updated.

    Declaration

    Swift

    public func refreshViews(refreshContext: TableRefreshContext = .unknown)