Skip to content

Commit

Permalink
Merge pull request #62 from pegurov/master
Browse files Browse the repository at this point in the history
Added support for table section index
  • Loading branch information
maxsokolov authored Apr 17, 2017
2 parents 92b3e3b + c277b65 commit 06becd8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
29 changes: 28 additions & 1 deletion Sources/TableDirector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ open class TableDirector: NSObject, UITableViewDataSource, UITableViewDelegate {
private weak var scrollDelegate: UIScrollViewDelegate?
private var cellRegisterer: TableCellRegisterer?
public private(set) var rowHeightCalculator: RowHeightCalculator?

private var sectionsIndexTitlesIndexes: [Int]?

@available(*, deprecated, message: "Produced incorrect behaviour")
open var shouldUsePrototypeCellHeightCalculation: Bool = false {
didSet {
Expand Down Expand Up @@ -192,6 +193,32 @@ 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]? {

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

if let title = section.indexTitle {
indexTitles.append(title)
indexTitlesIndexes.append(index)
}
}
if !indexTitles.isEmpty {

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

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

// MARK: UITableViewDelegate - actions

open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
Expand Down
1 change: 1 addition & 0 deletions Sources/TableSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
4 changes: 2 additions & 2 deletions TableKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand All @@ -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
end

0 comments on commit 06becd8

Please sign in to comment.