Re: Custom Sheets
Re: Custom Sheets
- Subject: Re: Custom Sheets
- From: matt neuburg <email@hidden>
- Date: Thu, 31 Jul 2003 03:57:29 -0700
On Tue, 29 Jul 2003 10:34:11 -0700, Seth Willits <email@hidden> said:
>
What are the steps to creating a custom sheet? When a button is clicked
>
I want to display a custom modal sheet where a user can enter some data
>
into a text field, but I can't figure out how make a sheet in Interface
>
Builder.
Just drag a panel into IB's main window. The panel will appear also as an open window. Drag the text field and anything else into that. Hook up outlets and actions as desired.
>
- (void)showCustomSheet: (NSWindow *)parentWindow
>
{
>
[NSApp beginSheet: sheetWindow
>
modalForWindow: parentWindow
>
modalDelegate: nil
>
didEndSelector: nil
>
contextInfo: nil];
>
[NSApp runModalForWindow: sheetWindow];
>
// Sheet is up here.
>
[NSApp endSheet: sheetWindow];
>
[sheetWindow orderOut: self];
>
}
Do not use runModalForWindow. That is for an application-modal dialog, not a sheet. A sheet is window-modal. If you don't want window-modality, don't use a sheet; use a dialog.
Sheets are a tripartite affair; that is, you handle a sheet by using three methods. (1) beginSheet: will typically be the *last* thing in your first method. Now the sheet is showing and window-modality has begun, and we return to an idle state. (2) The user can press buttons in the sheet; you are responsible for seeing to it that the action method of at least one of these ends the sheet by calling a form of endSheet:. This brings modality to an end, but the sheet is still showing. (3) The modalDelegate and didEndSelector together tell the application what method to call when modality ends. Look at NSApplication.h for the details on what the declaration of the selector pointed to by didEndSelector must look like. This method calls orderOut: and the sheet disappears. In real life you can often dispense with (3) and close the sheet in (2) instead. m.
--------
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.