dev*_*os1 3 cocoa nstoolbar nssegmentedcontrol responder-chain
请原谅这个超级菜鸟的问题,但在过去的一个小时里我一直在谷歌上搜索这个问题,我很沮丧,因为我似乎找不到这样一个非常基本的问题的答案:
我如何处理 Cocoa 中的控制更改?
我来自 iOS,很明显 Cocoa 并不像 UIKit 那样使用出口或委托来处理事件,我觉得我在这里错过了一些非常重要的信息。我已经发现它使用了第一响应者链,但除此之外我无法弄清楚如何实际做到这一点,或者如何找到这些事件的定义或记录位置。
所以我有一个NSSegmentedControl内部 a NSToolBar,我只想知道用户何时更改所选段。我已经仔细阅读了类文档,但没有看到任何提及要处理的任何类型的事件或操作。我确实注意到,如果我将控件的action出口拖到我的第一响应者代理上,我会列出一千万种不同的操作,其中没有一个看起来是相关的。
我到底该如何在 Cocoa 中做到这一点?
这是我的一个项目中的代码
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)")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1210 次 |
| 最近记录: |