我有 2 个组合框,它们使用与数据源相同的字典。在第一个组合框中将显示键,在第二个组合框中将显示值。
首先,我需要一些帮助来实现数据源委托方法;请参阅下面的代码清单。相关的盒子是 floorBox 和 roomsBox。忽略其他 2 个,因为它们将从局部变量或接口中填充。另外,假设一楼 [key = 0] 我有 3 个房间 [value = 3],我如何取 3 的值并将其变成 roomsBox 内的 3 个项目;这样每次地板改变房间的盒子都有相应数量的物品(如果有意义的话)。我真的很感谢你的帮助,我感谢你。
class RoomAndAlarmTypesVC: NSViewController, NSComboBoxDelegate, NSComboBoxDataSource {
//MARK: - Properties
private var floorsAndRooms = [String: String]()
@IBOutlet private weak var floorsBox: NSComboBox!
@IBOutlet private weak var roomsBox: NSComboBox!
@IBOutlet private weak var roomType: NSComboBox!
@IBOutlet private weak var alarmType: NSComboBox!
//MARK: - Actions
override func viewDidLoad() {
super.viewDidLoad()
floorsAndRooms = representedObject as! [String : String]
floorsBox.usesDataSource = true
roomsBox.usesDataSource = true
roomType.usesDataSource = true
alarmType.usesDataSource = true
floorsBox.delegate = self
roomsBox.delegate = self
roomType.delegate = self
alarmType.delegate = self
floorsBox.dataSource = self
roomsBox.dataSource = self
roomType.dataSource = self
alarmType.dataSource = self
}
@IBAction private func setTheSystem(_ sender: NSButton) {
}
func numberOfItems(in comboBox: NSComboBox) -> Int {
what do i do here?
}
func comboBox(_ comboBox: NSComboBox, objectValueForItemAt index: Int) -> Any? {
same here?
}
}