2016-04-25 128 views
0

我有NSWindow與自定義NSView。此自定義NSView覆蓋performDragOperation方法。拖放操作很好。但是當我創建並顯示NSAlert作爲模式窗口時,我需要阻止拖放操作,不應調用performDragOperation。如何在NSAlert顯示爲模式窗口時禁用所有拖放操作

NSAlert *alert = [[NSAlert alloc]init]; 
[alert addButtonWithTitle:@"Excellent"]; 
[alert setMessageText:@"This is your message."]; 
[alert runModal]; 

可能的解決方案之一是添加代碼,驗證是否顯示對話框執行DragOperation方法。但是如何檢測是否顯示NSAlert。 例如,對於片我可以使用:

if([window attachedSheet]) { 
    ... 
} 

但如何爲

[alert runModal]; 
+0

'NSApplication'有一個屬性'modalWindow'。 – Willeke

+0

謝謝Willeke。這正是我需要的。 –

回答

0

做到這一點根據Willeke意見,來檢測某些警報正在運行,可以使用下面的代碼:

if([NSApp modalWindow]) { 
    ... 
} 
相關問題