xcode 如何创建从 NSWindow 模态弹出的 NSPanel(可可编程)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13881164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a NSPanel modally popuped from NSWindow (Cocoa programming)
提问by droughtrain
like NSPanel displayed after a button clicked in the NSWindow.
就像在 NSWindow 中单击按钮后显示的 NSPanel。
I looked for a lot but there is no simple example. Thanks for any help.
我找了很多,但没有简单的例子。谢谢你的帮助。
回答by Justin Boo
It can be done like this:
可以这样做:
-(IBAction)showButtonAction:(id)sender {
[[NSApplication sharedApplication] beginSheet:panelOutlet
modalForWindow:self.window
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
Attention:
注意力:
Don't forget to uncheck
NSPanel
's Visible At Launchcheckbox in Attributes Inspectorand Release When Closedif you will use this panel not once.
如果您不打算使用此面板,请不要忘记取消选中Attributes Inspector 中
NSPanel
的Visible At Launch复选框 和Release When Closed。
Result:
结果: