Hide section header if passwords count is less than the threshold (fix #197, #227)

This commit is contained in:
Mingshen Sun 2019-11-17 16:49:14 -08:00
parent 937b826a4a
commit b9edcea214
No known key found for this signature in database
GPG key ID: 1F86BA2052FED3B4

View file

@ -21,6 +21,8 @@ fileprivate class PasswordsTableEntry : NSObject {
} }
} }
fileprivate let hideSectionHeaderTreshold = 6 // hide section header if passwords count is less than the threshold
class PasswordsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UITabBarControllerDelegate, UISearchBarDelegate { class PasswordsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UITabBarControllerDelegate, UISearchBarDelegate {
private var passwordsTableEntries: [PasswordsTableEntry] = [] private var passwordsTableEntries: [PasswordsTableEntry] = []
private var passwordsTableAllEntries: [PasswordsTableEntry] = [] private var passwordsTableAllEntries: [PasswordsTableEntry] = []
@ -373,11 +375,24 @@ class PasswordsViewController: UIViewController, UITableViewDataSource, UITableV
} }
} }
private func hideSectionHeader() -> Bool {
if passwordsTableEntries.count < hideSectionHeaderTreshold || self.searchController.isActive {
return true
}
return false
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if hideSectionHeader() {
return nil
}
return sections[section].title return sections[section].title
} }
func sectionIndexTitles(for tableView: UITableView) -> [String]? { func sectionIndexTitles(for tableView: UITableView) -> [String]? {
if hideSectionHeader() {
return nil
}
return sections.map { $0.title } return sections.map { $0.title }
} }