【问题标题】:Calling an NSAlert from didEndSelector of another NSAlert从另一个 NSAlert 的 didEndSelector 调用 NSAlert
【发布时间】:2010-12-05 13:11:19
【问题描述】:

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

有什么想法吗?

【问题讨论】:

    标签: objective-c cocoa macos nsalert


    【解决方案1】:

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

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

    这是文档:

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

    【讨论】:

      【解决方案2】:

      有一种更简单的方法,只需在 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];
                      }
      

      希望有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-08
        • 1970-01-01
        • 2013-01-27
        • 2018-04-21
        • 2015-03-09
        • 2011-04-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多