mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-01-17 22:19:08 +00:00
Drop OptionViewControllerDelegate, use blocks
This commit is contained in:
parent
8fd5a74dc4
commit
03dd33852b
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user