DynamicSectionIndexTitles

public final class DynamicSectionIndexTitles : SectionIndexTitles

Generates section index titles by fetching the first element of a section and transforms it with a given closure into a section index titles.

Example

//A data provider with multiple sections. Each section contains trains from a single type
let dataProvider: ArrayDataProvider<Train> = //

//Use type name as a section header and shortname as a section index title.
let sectionTitleProvider = DynamicSectionIndexTitles(dataProvider: dataProvider,
                               generateSectionIndexTitle: { train, _ in return train.type.shortName })
  • Section Index Titles for UITableView. Related to UITableViewDataSource method sectionIndexTitlesForTableView

    Declaration

    Swift

    public var sectionIndexTitles: [String]? { get }
  • Creates a DynamicHeaderTitlesProvider.

    Declaration

    Swift

    public init<D: DataProvider>(dataProvider: D,
                                 generateSectionIndexTitle: @escaping (D.Element, IndexPath) -> String,
                                 using element: SectionMetaData.SectionMetaDataElement)

    Parameters

    dataProvider

    the data provider used as source for header titles.

    generateSectionIndexTitle

    a closure to transform a Element which is part of the data provider into a single String, which is used as a section index titles.

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

    Declaration

    Swift

    public func indexPath(forSectionIndexTitle sectionIndexTitle: String,
                   at index: Int) -> IndexPath

    Parameters

    sectionIndexTitle

    The title as displayed in the section index

    index

    An index number identifying a section title in the array returned by sectionIndexTitles

    Return Value

    An index number identifying a section.