Skip to content

Commit

Permalink
Renamed to sectionsIndexTitlesIndexes, and it is now nil if not used
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel Gurov committed Apr 13, 2017
1 parent 39b4df6 commit c277b65
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Sources/TableDirector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate {
private weak var scrollDelegate: UIScrollViewDelegate?
private var cellRegisterer: TableCellRegisterer?
public private(set) var rowHeightCalculator: RowHeightCalculator?
private var sectionsIndex = [Int]()
private var sectionsIndexTitlesIndexes: [Int]?

@available(*, deprecated, message: "Produced incorrect behaviour")
open var shouldUsePrototypeCellHeightCalculation: Bool = false {
Expand Down Expand Up @@ -198,19 +198,25 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate {
public func sectionIndexTitles(for tableView: UITableView) -> [String]? {

var indexTitles = [String]()
sectionsIndex = []
var indexTitlesIndexes = [Int]()
sections.enumerated().forEach { index, section in

if let title = section.indexTitle {
indexTitles.append(title)
sectionsIndex.append(index)
indexTitlesIndexes.append(index)
}
}
return indexTitles.isEmpty ? nil : indexTitles
if !indexTitles.isEmpty {

sectionsIndexTitlesIndexes = indexTitlesIndexes
return indexTitles
}
sectionsIndexTitlesIndexes = nil
return nil
}

public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
return sectionsIndex[index]
return sectionsIndexTitlesIndexes?[index] ?? 0
}

// MARK: UITableViewDelegate - actions
Expand Down

0 comments on commit c277b65

Please sign in to comment.