@@ -31,7 +31,8 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate {
3131 private weak var scrollDelegate : UIScrollViewDelegate ?
3232 private var cellRegisterer : TableCellRegisterer ?
3333 public private( set) var rowHeightCalculator : RowHeightCalculator ?
34-
34+ private var sectionsIndexTitlesIndexes : [ Int ] ?
35+
3536 @available ( * , deprecated, message: " Produced incorrect behaviour " )
3637 open var shouldUsePrototypeCellHeightCalculation : Bool = false {
3738 didSet {
@@ -192,6 +193,32 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate {
192193 return section. footerHeight ?? section. footerView? . frame. size. height ?? UITableViewAutomaticDimension
193194 }
194195
196+ // MARK: UITableViewDataSource - Index
197+
198+ public func sectionIndexTitles( for tableView: UITableView ) -> [ String ] ? {
199+
200+ var indexTitles = [ String] ( )
201+ var indexTitlesIndexes = [ Int] ( )
202+ sections. enumerated ( ) . forEach { index, section in
203+
204+ if let title = section. indexTitle {
205+ indexTitles. append ( title)
206+ indexTitlesIndexes. append ( index)
207+ }
208+ }
209+ if !indexTitles. isEmpty {
210+
211+ sectionsIndexTitlesIndexes = indexTitlesIndexes
212+ return indexTitles
213+ }
214+ sectionsIndexTitlesIndexes = nil
215+ return nil
216+ }
217+
218+ public func tableView( _ tableView: UITableView , sectionForSectionIndexTitle title: String , at index: Int ) -> Int {
219+ return sectionsIndexTitlesIndexes ? [ index] ?? 0
220+ }
221+
195222 // MARK: UITableViewDelegate - actions
196223
197224 open func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
0 commit comments