2012-02-29 23 views
0

有沒有一種方法可以確定表單的狀態?我知道我可以調用這個方法:可可獲得表單狀態

- (void) customSheetDidClose : (NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo 

但我想要做的是這樣的:

- (void) getInfoMethod { 

    //...do a lot of stuff to gather data 

    [self openSheetMethod:dictionaryFullOfStuff]; 


    //I am completely making this up 
    while([panFileDataEditor state] == open) { 
     //do nothing 
    } 

} 

- (void) openSheetMethod : (NSDictionary*) stuff { 

    //...do something with stuff 

    [NSApp beginSheet: panFileDataEditor modalForWindow: window modalDelegate: self didEndSelector: @selector(customSheetDidClose:returnCode:contextInfo:) contextInfo: nil]; 

} 

我使用的是NSPanel我的表,我想我可以得到它的框架和檢查y位置,以確定其狀態,但我想檢查,看看是否有這樣的一個接受的方式...

+0

我重寫了谷歌的問題,並得到了這個:BOOL hasSheet =([window attachedSheet]!= nil); – PruitIgoe 2012-02-29 18:04:40

+0

我在google上重寫了這個問題,並得到了這個:BOOL hasSheet =([window attachedSheet]!= nil);更改我的代碼爲:while([winMain attachedSheet]!= nil){ \t \t \t NSLog(@ 「表單打開」); \t \t \t}但我不能在表單本身做任何事情 – PruitIgoe 2012-02-29 18:10:28

回答

0
BOOL hasSheet = ([window attachedSheet] != nil); 

只是爲了測試表是否存在; -[NSWindow attachedSheet]將返回表單,如果它存在,或者nil如果沒有。我不清楚你想要獲得什麼樣的「狀態」,但是

NSWindow * theSheet = [window attachedSheet]; 

確實會爲您提供表格本身。從那裏你可以做任何你喜歡的事情:[theSheet frame],例如

0

Cocoa是一個基於事件的系統,因此您不必等待事情在while循環中發生,而是您發現的方法在事件發生時由系統調用。所以沒有while循環。

您在類中實現了customSheetDidClose:returnCode:contextInfo:方法(不調用它),它將在表關閉時調用。

如果您希望在表單打開時自定義事件發生,請創建NSWindowController的子類來處理表單。