• 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: Sheets in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sheets in Cocoa


  • Subject: Re: Sheets in Cocoa
  • From: Chuck Norris <email@hidden>
  • Date: Fri, 26 Oct 2001 10:49:14 -0700

do they all have to be created programmatically?

Nope. You can do it programmatically with NSBeginAlertSheet and its brethren (and it's very handy to do this for simple error messages, etc.) but you can use nibs too.

There are lots of variations on this, but this should get you started. There is a lot I *don't* do in this example, but it's pulled from functioning code one of my apps, so it does work.

Start by creating a nib with some sort of window (mine was a ModalPanel - I'm not sure if it's critical). Using IB, set up some sort of outlet connection that gives you access to the window object after you load it from the nib. I just made the "File's Owner" be the most logical controller object inside my project and connected it to an IBOutlet NSWindow object defined in that controller's interface.

So your controller.h might look something like this:

@interface MyController : NSObject
{
IBOutlet NSWindow *sheetWindow;
}
@end

In IB, I hooked "sheetWindow" up to the window I defined in the nib.
Then, in your controller.m you might have something like this:

// Load the nib
if(![NSBundle loadNibNamed:@"MySheetNib" owner:self]) {
NSLog(@"Failed to load MySheetNib.nib");
return;
}

// Launch the sheet
[[NSApplication sharedApplication] beginSheet: sheetWindow
modalForWindow: targetWindow
modalDelegate: self
didEndSelector: nil
contextInfo: nil];

TargetWindow is of course the window you want the sheet to hook up to. And notice that I left didEndSelector nil - I chose to hook my sheet's controls up to methods in the controller, so I get all the information about what happened in the sheet that way - no need for a callback when the sheet ends in my case.

Hope this is useful.

Chuck


At 6:03 PM +0100 10/26/01, Ken Tabb wrote:
Hi,
is there something (else) I'm missing... I can't find any sheets stuff in
IB... do they all have to be created programmatically?

Thanks in advance,
Ken

----------------------------------------------
Ken Tabb
Mac & UNIX Propellerhead & Network Bloke (Health & Human Sciences)
Computer Vision / Neural Network researcher (Computer Science)
University of Hertfordshire
http://www.health.herts.ac.uk/ken/

Certified non-Microsoft Solution Provider
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


  • Follow-Ups:
    • calls to select seem to mess with NSTimers..
      • From: Charles Bennett <email@hidden>
  • Prev by Date: Re: Designing inspector palettes
  • Next by Date: Re: Changing Desktop picture from Cocoa app in 10.1 without re-starting Finder [Success!]
  • Previous by thread: Sheets in Cocoa
  • Next by thread: calls to select seem to mess with NSTimers..
  • Index(es):
    • Date
    • Thread