• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [Newbie] How to load and display a sheet from a NIB file ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Newbie] How to load and display a sheet from a NIB file ?


  • Subject: Re: [Newbie] How to load and display a sheet from a NIB file ?
  • From: Nick Zitzmann <email@hidden>
  • Date: Thu, 20 Mar 2003 03:29:18 -0800

On Thursday, March 20, 2003, at 02:43 AM, Jirome Foucher wrote:

This NIB file holds the window and 2 sheets.
I want to display the first sheet when the user click the "Add" button, and the second one when he/she clicks on the "Delete" button.

From my understanding, I should use the beginSheet method from NSApplication.
But I don't really understand how I should load the sheet from the NIB file....

Do I have to put each sheet into a separate NIB file ?

No, not unless you want to, anyway.

Do I need to create a custom class for each sheet too ?

No. What you do is this: (std. disclaimer: code typed in Mail, untested, use at your own risk, etc.)

1. Create two new panels ("NSPanel" class) in some nib loaded by your application, one for your Add button and one for your Delete button.
2. Make an outlet for each panel from the class you want to control them.
3. Use something like this for your Add button action:

- (IBAction)addButtonClicked:(id)sender
{
[NSApp beginSheet:ADD_SHEET modalForWindow:PARENT_WINDOW modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:nil];
}

Replace ADD_SHEET with the outlet name of the Add panel, and PARENT_WINDOW with the window outlet name that will display the sheet. If you want to redirect it to a different class, you can change modalDelegate: as well.

Now do something like that for your Delete button; you should know what to do. I'll use DELETE_SHEET below to mark the place where you use the sheet's outlet.

4. Create IBAction methods for the buttons on your Add & Delete panels (e.g. OK and Cancel buttons).

For example, to make an "OK" action, do this:

- (IBAction)okButtonClicked:(id)sender
{
if ([sender isKindOfClass:[NSButton class]] == YES)
{
[NSApp endSheet:[sender window] returnCode:NSRunStoppedResponse];
}
}

In a "Cancel" action, do this:

- (IBAction)cancelButtonClicked:(id)sender
{
if ([sender isKindOfClass:[NSButton class]] == YES)
{
[NSApp endSheet:[sender window] returnCode:NSRunAbortedResponse];
}
}

(You can actually return whatever return codes you want; I just used the return values from NSApplication's -runModalForWindow: method.)

5. Finally, create one more method in the "modal delegate" class from above. This can handle both sheets:

- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
{
switch (sheet)
{
case ADD_SHEET:
if (returnCode == NSRunStoppedResponse)
{
// The user clicked OK in the Add sheet, so do whatever...
}
[ADD_SHEET close];
break;
case DELETE_SHEET:
if (returnCode == NSRunStoppedResponse)
{
// The user clicked OK in the Delete sheet, so do whatever...
}
[DELETE_SHEET close];
break;
}
}

Then you just implement your OK button code in the place of those comments above, and it should all work... That's one way of doing sheets.

Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page: http://dreamless.home.attbi.com/

Smile! It confuses people!
_______________________________________________
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.

  • Follow-Ups:
    • Re: [Newbie] How to load and display a sheet from a NIB file ?
      • From: Jérome Foucher <email@hidden>
References: 
 >[Newbie] How to load and display a sheet from a NIB file ? (From: Jérome Foucher <email@hidden>)

  • Prev by Date: Re: Mouse and buttons
  • Next by Date: Re: MouseDown of superclass
  • Previous by thread: [Newbie] How to load and display a sheet from a NIB file ?
  • Next by thread: Re: [Newbie] How to load and display a sheet from a NIB file ?
  • Index(es):
    • Date
    • Thread