Cocoa Sheets How To

Sheets, of course, being those windows that drop down from the top of, and are attached to, another window. It’s pretty simple, but I had a hard time finding any documentation or Google info about it.  So here is what I finally found/figured out:

1. First create the windows or panels in Interface Builder that will be the sheet and the window/panel that the sheet is attached to. If your sheet is a panel, set the style to “Document Modal”.

2. Then do this in obj-c:

[NSApp beginSheet:mySheet modalForWindow:myPanel
     modalDelegate:self didEndSelector:NULL contextInfo:nil];
.
.
.
[NSApp endSheet:mySheet];
[mySheet orderOut:self];
[mySheet performClose:self];

I’m not sure if that last performClose statement is needed, but it can’t hurt.

2 Responses to “Cocoa Sheets How To”

  1. Matt Says:

    where are mySheet and myPanel defined? are they NSWindow instances?

  2. nick Says:

    You create the mySheet and myPanel in Interface Builder and then hook them to IBOutlets in your code. They are both NSPanel or NSWindow instances. It’s up to you.

Leave a Reply