Skip to content

Custom indexTitles #27

@wow-such-amazing

Description

@wow-such-amazing

Hello!

I have a suggestion to improve about indexTitles for sections.
Below is the current code for section indexes. It is based on the indexTitle property of the TableSection. However pretty common case is to have the full alphabet in the indexes even if your table contains only couple sections with titles like C and H. So I think the best way would be to somehow divide indexTitles from sections.

I will be able to make a PR about that as soon as we switch our project from FlowKit to Owl.

// MARK: - Section Indexes -
public func sectionIndexTitles(for tableView: UITableView) -> [String]? {
	let indexes = sections.compactMap({ $0.indexTitle })
	guard !indexes.isEmpty else {
		return nil
	}
	return indexes
}

public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
	return sections.firstIndex(where: { $0.indexTitle == title }) ?? 0
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions