Strange behavior with nib loading
Strange behavior with nib loading
- Subject: Strange behavior with nib loading
- From: "Carter R. Harrison" <email@hidden>
- Date: Sun, 8 Apr 2007 20:00:22 -0400
I've been trying to solve a mystery for the past day and half to no
avail, so maybe somebody here can shed some light on this. I've got
a Cocoa application that has some additional nib files. One nib file
has an instance of NSWindow that is to be used as a modal dialog box
within the main application. Inside that NSWindow I have a custom
subclass of NSView and it also is an instance within IB.
The File's Owner on the nib is a subclass of NSObject that has IB
connections to the top level objects (one of them goes to my nsview
subclass) I want to deal with from my code.
So I can make the sheet open correctly with the code below, but I
notice that my NSView subclass (one of the top-level objects in my
nib) is instantiating twice for some reason. It also doesn't appear
to be drawing correctly so I feel like it is trying to draw two
instances in the same window area. This can't be right, and I don't
want to forge ahead anymore until I figure out what is going on here.
Below is the code I have:
My main application has a controller object with the following method
that opens the sheet when the user clicks on a button.
- (IBAction)openSheet:(id)sender
{
CHPredicateBuilder *predicateBuilder = [[CHPredicateBuilder alloc]
init]; //See below for init method.
[predicateBuilder showCustomSheet:window]; //window is an IBOutlet
to the main application window.
[predicateBuilder release];
}
CHPredicateBuilder is the nib's File's Owner. It has the following
methods:
- (id)init
{
self = [super init];
if (self)
{
NSNib *nib = [[NSNib alloc]
initWithNibNamed:@"PredicateBuilderSheet" bundle:[NSBundle
bundleForClass:[self class]]];
if (![nib instantiateNibWithOwner:self topLevelObjects:nil])
{
NSLog(@"Warning! Could not load nib file.\n");
return nil;
}
[nib release];
}
return self;
}
- (void)showCustomSheet: (NSWindow *)window
{
[NSApp beginSheet: predicateSheet
modalForWindow: window
modalDelegate: self
didEndSelector: @selector(didEndSheet:returnCode:contextInfo:)
contextInfo: nil];
}
Thanks in advance!
Regards,
Carter
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden