moved indexTitle to TableSection

This commit is contained in:
Pavel Gurov 2017-04-13 11:37:08 +03:00
parent b49b01ff59
commit 39b4df6ee9
2 changed files with 14 additions and 6 deletions

View File

@ -31,8 +31,7 @@ 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)?
private var sectionsIndex = [Int]()
@available(*, deprecated, message: "Produced incorrect behaviour")
open var shouldUsePrototypeCellHeightCalculation: Bool = false {
@ -197,13 +196,21 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate {
// MARK: UITableViewDataSource - Index
public func sectionIndexTitles(for tableView: UITableView) -> [String]? {
return sectionIndexTitles
var indexTitles = [String]()
sectionsIndex = []
sections.enumerated().forEach { index, section in
if let title = section.indexTitle {
indexTitles.append(title)
sectionsIndex.append(index)
}
}
return indexTitles.isEmpty ? nil : indexTitles
}
public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
guard let onSectionForIndex = onSectionForIndex else { return 0 }
return onSectionForIndex(title, index)
return sectionsIndex[index]
}
// MARK: UITableViewDelegate - actions

View File

@ -26,6 +26,7 @@ open class TableSection {
open var headerTitle: String?
open var footerTitle: String?
open var indexTitle: String?
open var headerView: UIView?
open var footerView: UIView?