处理可可中的nsementedcontrol选定段变化



请原谅超级菜鸟问题,但是过去一个小时我一直在谷歌搜索它,并且感到沮丧,我似乎找不到这样一个非常基本的问题的答案:

如何处理可可的控制变化?

我来自iOS,很明显,可可(Cocoa(不使用插座或代表来处理与Uikit一样的方式处理活动,而且我觉得我只是在这里缺少一些非常重要的信息。我发现它使用了第一响应器链,但是除此之外,我无法弄清楚如何实际做,或者如何找到这些事件的定义或记录。

所以我在NSToolBar内有一个NSSegmentedControl,我只想知道用户何时更改所选段。我已经浏览了类文档,但看不到单一提及要处理的任何事件或动作。我确实注意到是否将控件的action插座拖到我的第一响应者代理上,我会列出了四千亿个不同的动作,它们似乎都没有任何相关。

我在可可中如何做到这一点?

这是我项目之一的代码

var currntSeg : Int = 1
@IBOutlet weak var acSwitch: NSSegmentedControl!
@IBAction func SwitchButton(_ sender: AnyObject) {
    switch acSwitch.selectedSegment {
    case 0:
        currntSeg == 0 ?
            self.navVC?.pushViewController(Sleeper!, animated: true) :
            self.navVC?.popViewController(Sleeper!, animated: true)
    case 1:
        currntSeg < 1 ?
            self.navVC?.pushViewController(Work!, animated: true) :
            self.navVC?.popViewController(Work!, animated: true)
    case 2:
        currntSeg < 2 ?
            self.navVC?.pushViewController(Student!, animated: true) :
            self.navVC?.popViewController(Student!, animated: true)
    default:
        self.navVC?.pushViewController(Rose!, animated: true)
    }
    currntSeg = acSwitch.selectedSegment
    print("Selected Seg: (acSwitch.selectedSegment)")
}

最新更新