我需要根据来自另一个NSAlert的响应调出一个NSAlert。但是,当我尝试从第一个didEndSelector调用它时,发生了各种糟糕的事情(比如我的文档窗口消失了,以及关于打印到控制台的排序问题的警告)。
有什么想法吗?
发布于 2009-10-10 06:03:18
你要做的就是“链接”警报。
为此,您需要在警报窗口上调用orderOut:。
以下是文档:
如果要在模式委托执行响应返回值的操作之前从alertDidEndSelector方法中清除工作表,请将orderOut:(NSWindow)发送到通过将window发送到alert参数而获得的window对象。这允许您链接工作表,例如,在alertDidEndSelector方法中显示下一张工作表之前先清除一张工作表。请注意,在调用alertDidEndSelector方法之前,应注意不要从程序中的其他位置调用orderOut:。
发布于 2009-10-11 04:04:42
有一种更简单的方法,只需在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];
}希望这能有所帮助
https://stackoverflow.com/questions/1547112
复制相似问题