如何创建自定义模态NSWindow? [英] How do I create a custom modal NSWindow?
问题描述
我想创建一个充当模式对话框的自定义NSWindow。通过自定义,我的意思是它在窗口中具有普通的用户控件,带有确定和取消按钮。该对话框将包含只读信息,并具有一些复选框,安全编辑字段等。
I want to create a custom NSWindow that acts as a modal dialog. By custom I mean it has normal user controls in the window, with a "OK" and "Cancel" buttons. The dialog will contain read only information, and have a few checkboxes, secure edit fields, etc.
MainMenu.xib文件将在启动时显示正常的Window,以及包括自定义的NSWindow(在启动时不可见)。
The MainMenu.xib file will have the normal Window visible at launch, plus include the custom NSWindow (which is NOT visible at launch).
我正在尝试查找示例代码以模态模式启动窗口(在应用程序初始化并启动main之后窗口),然后在确定上运行一个过程,并在该过程成功后隐藏对话框。否则,如果失败,请继续打开对话框,但在对话框上显示错误表。
I am trying to find example code to launch the window in modal mode (after the app initializes and launches main window), and on "OK" run a process, and on success of that process hide the dialog. Or on failure, keep the dialog up, but show an error sheet on the dialog.
感谢您的帮助。
推荐答案
您要查看 NSApplication
的 -runModalForWindow:
和/或 -runModalSession:
方法。请注意,使用模式窗口通常不是一个好主意,如果有可能避免这样做,则应该;也就是说,有时需要。
You want to look at NSApplication
’s -runModalForWindow:
and/or -runModalSession:
methods. Note that using modal windows is generally a bad idea and if it’s at all possible to avoid doing so, you should; that said, sometimes needs must.
就启动一个流程,等待其完成等而言,您可以使用<$ c $来完成所需的工作。 c> NSTask ,尽管您没有提供足够的细节来确定。您可能想观察 NSTaskDidTerminateNotification
来告诉您任务何时完成。
As far as launching a process, waiting for it to finish and so on, you can probably do what you need with NSTask
, although you don’t provide sufficient detail to be certain. You’d probably want to observe NSTaskDidTerminateNotification
to tell you when the task had finished.
请参见
有关<$ c的更多信息$ c> NSTask 和
有关模式的更多信息NSWindow
的用法。
这篇关于如何创建自定义模态NSWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!