0
我有一个非常简单的用户界面,只有一个NSPopUpButton
。其selectedIndex
绑定到int
值ViewController.self.my_selection
。只要我从UI中更改选择(即选择NSPopUpButton的第三项),我就会看到my_selection
值发生了变化。到目前为止这么好,我试图获得的是相反的方向。我想以编程方式更改my_selection
值,并查看NSPopUpButton
选择项目作为我在my_selection
中定义的索引。我错误地假设的行为是对绑定的默认行为......绑定和NSPopUpButton:更改当前键的值不会改变选择
这就是我现在获得:
NSPoPUpButton ---> select item at index 2 ----> my_selection becomes equal to 2
这就是我想要的实现(也保持在以前的行为)
my_selection ---> set value to 3----> NSPoPUpButton selected index = 3
你能告诉我们的实际代码?特别是,你如何在你的''ViewController''类中定义''my_selection''? –