从另一个 NSAlert 的 didEndSelector 调用一个 NSAlert

发布于 2024-08-06 20:02:35 字数 133 浏览 1 评论 0原文

我需要根据另一个 NSAlert 的响应来调出一个 NSAlert。但是,当我尝试从第一个的 didEndSelector 调用它时,会发生各种令人讨厌的事情(例如我的文档窗口消失以及有关打印到控制台的排序问题的警告)。

有什么想法吗?

I need to bring up an NSAlert based on the response from another NSAlert. However, when I try to call it from the didEndSelector of the first one, all kinds of nasty things happen (like my document window disappearing and warnings about ordering problems printing to console).

Any thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最单纯的乌龟 2024-08-13 20:02:35

您要做的就是“链接”警报。

为此,您需要在警报窗口上调用 orderOut:

这是文档:

如果您想从
在alertDidEndSelector方法中
在模态委托执行之前
响应返回的动作
值,发送 orderOut: (NSWindow) 到
发送得到的window对象
警报参数的窗口。这
允许您链接床单,用于
例如,通过忽略一张纸
在显示下一个之前
AlertDidEndSelector 方法。笔记
你应该小心不要打电话
orderOut:在其他地方的工作表上
在你的程序之前
调用alertDidEndSelector方法。

What you're trying to do is "chain" the alerts.

To do this you need to call orderOut: on the alert window.

Here's the documentation:

If you want to dismiss the sheet from
within the alertDidEndSelector method
before the modal delegate carries out
an action in response to the return
value, send orderOut: (NSWindow) to
the window object obtained by sending
window to the alert argument. This
allows you to chain sheets, for
example, by dismissing one sheet
before showing the next from within
the alertDidEndSelector method. Note
that you should be careful not to call
orderOut: on the sheet from elsewhere
in your program before the
alertDidEndSelector method is invoked.

一紙繁鸢 2024-08-13 20:02:35

有一个更简单的方法,只需检查 if 语句中 [runModal] 的内容:

//setup the dialog
NSAlert *networkErrorDialog = [NSAlert alertWithMessageText:@"Couldn't connect to the server" defaultButton:@"Network Diagnostics" alternateButton:@"Quit" otherButton:nil informativeTextWithFormat:@"Check that your computer is connected to the internet and make sure you aren't using a proxy server or parental controls"];

//show the dialog inside an IF, 0=the first button 1=the 2nd button etc
                if ([networkErrorDialog runModal]==0) {
                    //quit
                    [[NSApplication sharedApplication] terminate:self];
                } else {
                    //Network Diagnostics
                    [[NSWorkspace sharedWorkspace] launchApplication:@"Network Diagnostics"];
                    [[NSApplication sharedApplication] terminate:self];
                }

希望有帮助

There is an easier way, simply check the contents of [runModal] in an if statement:

//setup the dialog
NSAlert *networkErrorDialog = [NSAlert alertWithMessageText:@"Couldn't connect to the server" defaultButton:@"Network Diagnostics" alternateButton:@"Quit" otherButton:nil informativeTextWithFormat:@"Check that your computer is connected to the internet and make sure you aren't using a proxy server or parental controls"];

//show the dialog inside an IF, 0=the first button 1=the 2nd button etc
                if ([networkErrorDialog runModal]==0) {
                    //quit
                    [[NSApplication sharedApplication] terminate:self];
                } else {
                    //Network Diagnostics
                    [[NSWorkspace sharedWorkspace] launchApplication:@"Network Diagnostics"];
                    [[NSApplication sharedApplication] terminate:self];
                }

Hope that helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文