Drop empty space between Account sections

Reuse code for heightForHeader.
This commit is contained in:
Davide De Rosa 2019-04-04 19:53:08 +02:00
parent e4088aa8f3
commit 97db759242
4 changed files with 32 additions and 17 deletions

View File

@ -34,3 +34,25 @@ extension UIViewController {
navigationItem.largeTitleDisplayMode = theme.detailTitleDisplayMode
}
}
extension TableModel {
func headerHeight(for section: Int) -> CGFloat {
guard let title = header(for: section) else {
return 1.0
}
guard !title.isEmpty else {
return 0.0
}
return UITableView.automaticDimension
}
func footerHeight(for section: Int) -> CGFloat {
guard let title = footer(for: section) else {
return 1.0
}
guard !title.isEmpty else {
return 0.0
}
return UITableView.automaticDimension
}
}

View File

@ -103,6 +103,7 @@ class AccountViewController: UIViewController, TableModelHost {
model.add(.noAccount)
model.set([], in: .noAccount)
model.setHeader("", for: .credentials)
if guidance != nil {
let footer: String
if let _ = guidanceURL {
@ -184,6 +185,10 @@ extension AccountViewController: UITableViewDataSource, UITableViewDelegate, Fie
return model.footer(for: section)
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return model.headerHeight(for: section)
}
func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
var optButton = view.viewWithTag(AccountViewController.footerButtonTag + section) as? UIButton
if optButton == nil {

View File

@ -219,13 +219,7 @@ extension ConfigurationViewController: UITableViewDataSource, UITableViewDelegat
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard let title = model.header(for: section) else {
return 1.0
}
guard !title.isEmpty else {
return 0.0
}
return UITableView.automaticDimension
return model.headerHeight(for: section)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

View File

@ -593,16 +593,6 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
return model.header(for: section)
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
guard let title = model.header(for: section) else {
return 1.0
}
guard !title.isEmpty else {
return 0.0
}
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
let rows = model.rows(for: section)
if rows.contains(.providerRefresh), let date = lastInfrastructureUpdate {
@ -611,6 +601,10 @@ extension ServiceViewController: UITableViewDataSource, UITableViewDelegate, Tog
return model.footer(for: section)
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return model.headerHeight(for: section)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return model.count(for: section)
}