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 位置以确定它的状态,但我想检查是否有可接受的方式来执行此操作......

4

2 回答 2

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

仅用于测试工作表是否存在;-[NSWindow attachedSheet]如果它在那里,将返回工作表,否则nil。我不清楚您要获得什么“状态”,但是

NSWindow * theSheet = [window attachedSheet];

确实给你工作表本身。从那里你可以做任何你喜欢的事情:[theSheet frame]例如

于 2012-02-29T19:10:01.377 回答
0

Cocoa 是一个基于事件的系统,因此您不必在 while 循环中等待事情发生,而是在事情发生时系统调用您编写的方法。所以没有while循环。

您在类中实现 customSheetDidClose:returnCode:contextInfo: 方法(不调用它),当工作表关闭时将调用它。

如果您希望在工作表打开时发生自定义事情,请创建一个 NSWindowController 的子类来处理工作表。

于 2012-02-29T23:48:23.063 回答