diff --git a/Sources/TableDirector.swift b/Sources/TableDirector.swift index 808d4be..925aeb0 100644 --- a/Sources/TableDirector.swift +++ b/Sources/TableDirector.swift @@ -31,7 +31,9 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { private weak var scrollDelegate: UIScrollViewDelegate? private var cellRegisterer: TableCellRegisterer? public private(set) var rowHeightCalculator: RowHeightCalculator? - + public var sectionIndexTitles: [String]? + public var onSectionForIndex: ((_ title: String, _ index: Int) -> Int)? + @available(*, deprecated, message: "Produced incorrect behaviour") open var shouldUsePrototypeCellHeightCalculation: Bool = false { didSet { @@ -192,6 +194,18 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate { return section.footerHeight ?? section.footerView?.frame.size.height ?? UITableViewAutomaticDimension } + // MARK: UITableViewDataSource - Index + + public func sectionIndexTitles(for tableView: UITableView) -> [String]? { + return sectionIndexTitles + } + + public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int { + guard let onSectionForIndex = onSectionForIndex else { return 0 } + + return onSectionForIndex(title, index) + } + // MARK: UITableViewDelegate - actions open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { diff --git a/TableKit.podspec b/TableKit.podspec index 22d3c4c..260e2cc 100644 --- a/TableKit.podspec +++ b/TableKit.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = 'TableKit' s.module_name = 'TableKit' - s.version = '2.3.1' + s.version = '2.4.0' s.homepage = 'https://github.com/maxsokolov/TableKit' s.summary = 'Type-safe declarative table views with Swift.' @@ -14,4 +14,4 @@ Pod::Spec.new do |s| s.source_files = 'Sources/*.swift' s.source = { :git => 'https://github.com/maxsokolov/TableKit.git', :tag => s.version } -end \ No newline at end of file +end