forked from AgoraIO/API-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingCells.swift
More file actions
57 lines (48 loc) · 1.57 KB
/
SettingCells.swift
File metadata and controls
57 lines (48 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// SettingCells.swift
// APIExample
//
// Created by XC on 2020/12/15.
// Copyright © 2020 Agora Corp. All rights reserved.
//
import Foundation
class SettingsBaseParam: NSObject {
var key: String
var label: String
var type: String
init(type: String, key: String, label: String) {
self.type = type
self.key = key
self.label = label
}
}
class SettingBaseCell<T: SettingsBaseParam>: NSTableCellView {
var configs: T?
weak var delegate: SettingsViewControllerDelegate?
func configure(config: T) {
self.configs = config
}
}
class SettingsSelectParam<T>: SettingsBaseParam {
var value: String
var settingItem: SettingItem<T>
weak var context: NSViewController?
init(key: String, label: String, settingItem: SettingItem<T>, context: NSViewController) {
self.settingItem = settingItem
self.context = context
self.value = settingItem.selectedOption().label
super.init(type: "SelectCell", key: key, label: label)
}
}
class SettingSelectCell<T>: SettingBaseCell<SettingsSelectParam<T>> {
@IBOutlet weak var label: NSTextField?
@IBOutlet weak var picker: NSPopUpButton!
override func configure(config: SettingsSelectParam<T>) {
super.configure(config: config)
self.label?.cell?.title = config.label
self.picker?.addItems(withTitles: config.settingItem.options.map({ (option: SettingItemOption<T>) -> String in
return option.label
}))
self.picker?.selectItem(at: config.settingItem.selected)
}
}