0

Is there a way to determine the state of a sheet? I know I can call this method:

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

but what I want to do is something like this:

- (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];

}

I'm using a NSPanel for my sheet, I was thinking I could get its frame and check the y location to determine its status but I wanted to check to see if there was an accepted way of doing this...

Anoop Vaidya
  • 46,283
  • 15
  • 111
  • 140
PruitIgoe
  • 6,166
  • 16
  • 70
  • 137
  • I reworded the question on google and got this: BOOL hasSheet = ([window attachedSheet] != nil); – PruitIgoe Feb 29 '12 at 18:04
  • I reworded the question on google and got this: BOOL hasSheet = ([window attachedSheet] != nil);, changed my code to this: while([winMain attachedSheet] != nil) { NSLog(@"the sheet is open"); } but I then can't do anything in the sheet itself – PruitIgoe Feb 29 '12 at 18:10

2 Answers2

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

is only meant to test whether the sheet exists; -[NSWindow attachedSheet] will return the sheet if it's there, or nil if not. I'm not clear on what "state" you're trying to get, but

NSWindow * theSheet = [window attachedSheet];

does give you the sheet itself. From there you can do whatever you like: [theSheet frame], e.g.

jscs
  • 63,694
  • 13
  • 151
  • 195
0

Cocoa is an event based system so you don't wait for things to happen in a while loop, instead methods you write are called by the system when things happen. So no while loops.

You implement the customSheetDidClose:returnCode:contextInfo: method (not call it) in your class and it will be called when the sheet closes.

If you want custom things to happen when the sheet is open create a subclass of NSWindowController to handle the sheet.

Nathan Kinsinger
  • 23,641
  • 2
  • 30
  • 19