在 Cocoa Objective-C 中创建模态对话框或窗口? [英] Creating a Modal Dialog or Window in Cocoa Objective-C?

查看:30
本文介绍了在 Cocoa Objective-C 中创建模态对话框或窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个模态对话框,它是从一个 nib 文件加载的,并且应该在主窗口中单击按钮时显示.

I need to create an modal dialog, which is to loaded from a nib file and should be displayed on a button click in the main window.

我可以在 nib 文件中创建自定义窗口并在单击按钮时加载自定义对话框,但它不是模式对话框.我可以切换回主窗口.

I can create a custom window in a nib file and load the custom dialog on button click, but it's not a modal dialog. I can switch back to the main window.

MyWindowControllerNSWindowController 子类.我使用下面的代码来显示我的窗口以响应按钮事件:

MyWindowController is the NSWindowController subclass. I used the code below to display my window in response to the button event:

MyWindowController *pController = [[MyWindowController alloc] 
                                   initWithWindowNibName:@"nibfilename"];
[MyWindowController showWindow:self];

推荐答案

有几种方法可以做到这一点——实际上 OS X 中有两种不同的模态对话框:application-modal 和 window-modal.用错了会惹恼人.一个是工作表,它附加到它影响的窗口(保存对话框就是一个例子).另一个是应用程序模式,它会阻止整个应用程序(打开对话框以这种方式工作,因为它们不适用于任何尚不存在的窗口).Apple 的 工作表文档 应该可以帮助您定位.

There are several ways to do this — and in fact two different kinds of modal dialog in OS X: application-modal and window-modal. Using the wrong one will annoy people. One is a sheet, which is attached to the window that it affects (save dialogs are an example of this). The other is application-modal, which blocks the whole application (open dialogs work this way, since they don't apply to any window that exists yet). Apple's sheet documentation should help get you oriented.

这篇关于在 Cocoa Objective-C 中创建模态对话框或窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆