2014-10-02 26 views
5

根據Apple's documentation,似乎顯示警報表的唯一未棄用的方法是beginSheetModalForWindow:completionHandler:,其中completionHandler塊的參數爲NSModalResponse -type。 NSModalResponse是僅具有3 possible values的枚舉:NSModalResponseStopNSModalResponseAbortNSModalResponseContinue。那麼如何知道用戶點擊了警報表上的哪個按鈕?捕獲OS X 10.9+警報表的返回碼的正確方法是什麼?

+0

枚舉中的所有3個NSModalResponse值都是負值。嘗試記錄傳遞給完成處理程序的值,如果適用,也許它會傳遞單擊的按鈕索引。 – Greg 2014-10-02 23:27:05

回答

3

結果代碼實際上並不是一個枚舉,因爲它不僅限於NSModalResponse類型的值。枚舉僅用於定義的某些的可能值。

見的NSAlert-addButtonWithTitle:方法的文檔,例如,這解釋了從添加的按鈕產生的響應代碼:用於所述第二對NSAlertFirstButtonReturn用於第一,NSAlertSecondButtonReturnNSAlertThirdButtonReturn用於第三,和NSAlertThirdButtonReturn + Ñ後續按鈕。

又見了-runModal方法的文檔:

如果使用alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat:創建警報,以下常量用來標識用於解除警報按鈕:NSAlertDefaultReturnNSAlertAlternateReturnNSAlertOtherReturn。否則,使用的常量是那些在「Button Return Values.」

這是適用於傳遞給你提供給-beginSheetModalForWindow:completionHandler:完成處理的響應代碼相同的規則描述。

相關問題