Drop OptionViewControllerDelegate, use blocks

This commit is contained in:
Davide De Rosa 2019-04-06 16:05:13 +02:00
parent 8fd5a74dc4
commit 03dd33852b

View File

@ -25,12 +25,6 @@
import UIKit
protocol OptionViewControllerDelegate: class {
func optionController<T: Hashable>(_: OptionViewController<T>, descriptionFor option: T) -> String
func optionController<T: Hashable>(_: OptionViewController<T>, didSelect option: T)
}
class OptionViewController<T: Hashable>: UIViewController, UITableViewDataSource, UITableViewDelegate {
private lazy var tableView = UITableView(frame: .zero, style: .grouped)
@ -42,8 +36,6 @@ class OptionViewController<T: Hashable>: UIViewController, UITableViewDataSource
var selectionBlock: ((T) -> Void)?
weak var delegate: OptionViewControllerDelegate?
override func viewDidLoad() {
super.viewDidLoad()
@ -63,13 +55,13 @@ class OptionViewController<T: Hashable>: UIViewController, UITableViewDataSource
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let opt = options[indexPath.row]
let cell = Cells.setting.dequeue(from: tableView, for: indexPath)
cell.leftText = descriptionBlock?(opt) ?? delegate?.optionController(self, descriptionFor: opt)
cell.leftText = descriptionBlock?(opt)
cell.applyChecked(opt == selectedOption, Theme.current)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let opt = options[indexPath.row]
selectionBlock?(opt) ?? delegate?.optionController(self, didSelect: opt)
selectionBlock?(opt)
}
}