zou*_*oul 5 cocoa nswindow nswindowcontroller
我有一个对话窗口,可以通过自定义取消按钮或使用系统红色窗口按钮取消.取消对话框时,我需要执行一些简单的逻辑.如何检测到用户按下了红色按钮?
我知道我可以使用-windowWillClose:委托回调检测正在关闭的窗口.但是,当对话成功后以编程方式关闭窗口时,也会调用此回调.我也知道我可以简单地设置一个BOOL标志,但有更好的解决方案吗?如果我能检测到红色按钮激活,那将是最好的.
Ann*_*nne 14
定义关闭按钮:
NSButton *closeButton = [self standardWindowButton:NSWindowCloseButton];
Run Code Online (Sandbox Code Playgroud)
连接关闭按钮到自定义选择器:
[closeButton setTarget:self.delegate];
[closeButton setAction:@selector(closeThisWindow)];
Run Code Online (Sandbox Code Playgroud)
手动运行特定代码并关闭窗口.
-(void)closeThisWindow {
//
// The NSWindowCloseButton has been clicked.
// Code to be run before the window closes.
//
[self close];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2146 次 |
| 最近记录: |