[英]How to dismiss NSViewController when NSButton is clicked programmatically
How can I dismiss a NSViewController when a subview NSButton is clicked? 单击子视图NSButton时如何关闭NSViewController?
I can't access to NSViewController from function of NSButton mouseDown so I can't write a code similar to: 我无法从NSButton mouseDown函数访问NSViewController,所以无法编写类似于以下代码:
self.viewController.dismissController(self)
I need to set this programmatically, the same result when you connect via Assistant Editor a NSButton Action to its owner ViewController. 当您通过助手编辑器将NSButton Action连接到其所有者ViewController时,我需要以编程方式设置此结果。
You can manually set the target and action on controls in code. 您可以在代码中手动设置控件的目标和操作。
In your view controller: 在您的视图控制器中:
self.button.target = self;
self.button.action = @selector(dismissController:);
Should be good to go. 应该很好走。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.