我需要根據另一個NSAlert的響應調出一個NSAlert。但是,當我嘗試從第一個didEndSelector中調用它時,會發生各種令人討厭的事情(比如我的文檔窗口消失以及有關將問題打印到控制檯的警告)。從另一個NSAlert的didEndSelector調用NSAlert
有什麼想法?
我需要根據另一個NSAlert的響應調出一個NSAlert。但是,當我嘗試從第一個didEndSelector中調用它時,會發生各種令人討厭的事情(比如我的文檔窗口消失以及有關將問題打印到控制檯的警告)。從另一個NSAlert的didEndSelector調用NSAlert
有什麼想法?
你想要做的是「連鎖」警報。
爲此,您需要在警報窗口中撥打orderOut:
。
這裏的文檔:
如果你想模態委託之前拒絕來自 的alertDidEndSelector方法 之內的紙張進行 響應返回 值的動作,發送orderOut:(NSWindow )到 通過向警報參數發送 窗口獲得的窗口對象。這個 允許你鏈表,例如 的例子,通過在顯示下一個 之前關閉一張 alertDidEndSelector方法。注意 您應該注意不要致電 orderOut:在 之前 alertDidEndSelector方法被調用之前,從其他地方 的工作表。
還有一個更簡單的方法,只需檢查[runModal]
內容在if語句:
//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];
}
希望幫助