• 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: Dynamically loading NIB files into sheets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dynamically loading NIB files into sheets


  • Subject: Re: Dynamically loading NIB files into sheets
  • From: Chris Giordano <email@hidden>
  • Date: Wed, 17 Apr 2002 12:22:44 -0400

Sebastian,

On Tuesday, April 16, 2002, at 12:31 PM, Chris Giordano wrote:

I just put together a quick example of something similar, and can get a sheet to attach to a document window from either the document nib or from another nib file loaded through a controller object. One big difference is that my controller just inherits from NSObject and has an outlet for the sheet window. As such, my init is a bit different

Hmmm... I was considering the fact that maybe I was initializing my WindowController incorrectly. I've gotten sheets to work if the controller inherits from NSObject, but not NSWindowController. Do you think you might have time to test if you are able to display a sheet on a document window that is controlled by a class that inherits from NSWindowController that loads its own nib file (like I am doing)? If so, I bet we could figure out my problem.

First, I created a nib file called WCSheet.nib that had a window with an NSTextField label and an NSButton, and had the window connected to the window outlet that was there by virtue of being a subclass of NSWindowController. I created a subclass of NSWindowController (called WCSheet), using wcSheet = [[WCSheet alloc] initWithWindowNibName:@"WCSheet"], wcSheet being an outlet of my document class. I did this in the windowControllerDidLoadNib: method of my document class. I then created a sheet using the following method in my document class:

- (IBAction) openWCSheet:(id) sender
{
[NSApp beginSheet:[wcSheet window]
modalForWindow:docWindow
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
}

Again, the docWindow is an outlet that I attached to my document window in the document nib. This gave me a sheet attached to my document window.

For reference, I'm including the relevant code at the bottom of this message. If you'd like me to, I can make the project that I'm working with available so you can see everything that I'm doing.

However, I can produce what sound like the results you get (a floating sheet not attached to any window) by using the passing nil as the modalForWindow: parameter:

The question is... does that sheet have a title bar? When I passed in nil, the sheet was displayed with a title bar (but only the title was in the bar... no close/minimize buttons). When I pass in myDocumentWindow, the sheet is again floating by itself, but this time it does not have a title bar at all. It looks just like a sheet... only it is not attached to anything.

Yes, that sheet does have a title bar. I also get a title bar using the WCSheet sheet attached to nil, so clearly something different is happening.

By the way, I saw that you checked that theSheetController's window was what you thought it should be. What do you get when you do this on the document window (ReferenceDocumentWindow)? Are you sure that what ReferenceDocumentWindow refers to is the visible window? Just a thought.

To follow up on that myself, I decided to create a new window in the document nib file. I added the outlet "invisibleWindow" to the MyDocument class, and attached the new window in the document nib to this outlet. When I attach a sheet to this, I get a sheet floating with no titlebar. The window never appears on screen -- just the sheet. So given this, I'd guess that you're attaching it to a window that isn't on screen. If nothing else, what you're seeing is consistent with this.

Thanks again. I really hope to get this problem pinned down soon (pun intended... I'm in need of some levity, right now :-)

Good luck. Hope this helps.

chris

-----------

Here is the code that I'm using to get all of this.

// ----------- MyDocument.h ------------
#import <Cocoa/Cocoa.h>
#import "sheet.h"
#import "WCSheet.h"

@interface MyDocument : NSDocument
{
IBOutlet NSWindow * sheetA;
MySheet * sheetB;
IBOutlet NSWindow * docWindow;
WCSheet * wcSheet;
IBOutlet NSWindow * invisibleWindow;
}

- (IBAction) openSheetOne:(id) sender;
- (IBAction) openSheetTwo:(id) sender;
- (IBAction) openWCSheet:(id) sender;
- (IBAction) endSheet:(id) sender;
@end


// ----------- MyDocument.m ------------
#import "MyDocument.h"

@implementation MyDocument

- (NSString *)windowNibName
{
return @"MyDocument";
}

- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
sheetB = [[MySheet alloc] init];
wcSheet = [[WCSheet alloc] initWithWindowNibName:@"WCSheet"];
}

- (NSData *)dataRepresentationOfType:(NSString *)aType
{
// Insert code here to write your document from the given data. You can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.
return nil;
}

- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
// Insert code here to read your document from the given data. You can also choose to override -loadFileWrapperRepresentation:ofType: or -readFromFile:ofType: instead.
return YES;
}

- (IBAction) openSheetOne:(id) sender
{
[NSApp beginSheet:sheetA
modalForWindow:docWindow
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
}

- (IBAction) openSheetTwo:(id) sender
{
[NSApp beginSheet:[sheetB mySheet]
modalForWindow:docWindow
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
}

- (IBAction) openWCSheet:(id) sender
{
NSLog(@"the invisible window: (%@), it's title (%@)", invisibleWindow, [invisibleWindow title]);
NSLog(@"is the invisibleWindow visible? %@", ([invisibleWindow isVisible] ? @"Yes" : @"No"));
[NSApp beginSheet:[wcSheet window]
modalForWindow:invisibleWindow
modalDelegate:nil
didEndSelector:nil
contextInfo:nil];
}

- (IBAction) endSheet:(id) sender
{
[NSApp endSheet:[sender window]];
[[sender window] orderOut:self];
}

@end

// ----------- sheet.h ------------
#import <Cocoa/Cocoa.h>

@interface MySheet : NSObject
{
IBOutlet NSWindow * myWindow;
}

- (NSWindow *) mySheet;
- (IBAction) endSheet:(id) sender;
@end

// ----------- sheet.m ------------
#import "sheet.h"

@implementation MySheet

- (id) init
{
self = [super init];
if (self)
{
[NSBundle loadNibNamed:@"Sheet2" owner:self];
}
return self;
}

- (NSWindow *) mySheet
{
NSLog(@"getting MySheet's window: %@", myWindow);
return myWindow;
}

- (IBAction) endSheet:(id) sender
{
NSLog(@"in -[MySheet endSheet:]");
[NSApp endSheet:[sender window]];
[[sender window] orderOut:self];
}

@end

// ----------- WCSheet.h ------------
#import <AppKit/AppKit.h>

@interface WCSheet : NSWindowController {}

- (IBAction) endSheet:(id) sender;
@end

// ----------- WCSheet.m ------------
#import "WCSheet.h"

@implementation WCSheet

- (IBAction) endSheet:(id) sender
{
[NSApp endSheet:[sender window]];
[[sender window] orderOut:self];
}

@end
_______________________________________________
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.

References: 
 >Re: Dynamically loading NIB files into sheets (From: Sebastian Celis <email@hidden>)

  • Prev by Date: Re: Crossing the NIB?
  • Next by Date: Re: Looking for a time entry control for Cocoa
  • Previous by thread: Re: Dynamically loading NIB files into sheets
  • Next by thread: Dragging, aliases, and the Finder
  • Index(es):
    • Date
    • Thread