Re: NSPanel nib with NSWindowController
Re: NSPanel nib with NSWindowController
- Subject: Re: NSPanel nib with NSWindowController
- From: Chuck Soper <email@hidden>
- Date: Thu, 14 Aug 2003 12:12:57 -0700
At 1:52 PM -0400 8/14/03, Bill Cheeseman wrote:
on 03-08-14 1:09 PM, Chuck Soper at email@hidden wrote:
Can I have a nib that contains a panel (with no window) whose File's
Owner is a NSWindowController subclass?
I do it all the time.
NSPanel is a subclass of NSWindow, so whatever works for windows works for
panels, plus some.
Well, my NSPanel is showing properly now and I didn't change
anything... I was allocating the controller correctly and my
connections were fine. Project Builder crashed and I decided to toss
my entire build directory. When I re-built my application the panel
was showing correctly. I suspect I had some corrupt object files. My
class browser within PB hadn't been working for several weeks.
Previously without success I would quit PB, trash my build directory
(and empty the trash), and rebuild my application in an attempt to
get the class browser working - nothing worked. Now, my class browser
works fine.
I wish I had a reproducible so that I could file a bug (if it was a bug).
I take a different approach than yours, though. I don't see anything in your
example that indicates you have allocated and initialized the panel's window
controller, which may be your problem.
My menu item's action method allocates and initializes the panel's
NSWindowController subclass, like so:
[[MyPanelController alloc] init];
Then my action method does a couple of other things, like assigning the
newly allocated controller to an instance variable where the rest of my app
can get at it, and calling a couple of methods of the newly allocated
controller to set its own instance variables to objects in my main app that
the controller needs access to.
Finally, my action method forces the panel (window) to load and display,
like so:
[[self myPanelController] window];
[[self myPanelController] showWindow:sender];
(You may not need both of these messages. I've left out some irrelevant
detail that makes it necessary in my app.)
From my application controller:
- (IBAction)showInfoWindow:(id)sender
{
if (myPanelController == nil) {
myPanelController = [[InfoController alloc] initWithWindowNibName:@"Info"];
}
[myPanelController showWindow:self];
}
This worked but, I think "showWindow:self" was an error. I got this
code from the Apple "SimpleMultiWindow" IB sample. I think it should
be "showWindow:sender".
From your suggestion, I have since changed that line to:
[myPanelController window];
[myPanelController showWindow:sender];
I call -initwithWindowNibName: in my panel controller's -init method, so it
gets called when I allocate and init my panel controller in the action
method.
I currently allocate my myPanelController within the action method with:
myPanelController = [[InfoController alloc] initWithWindowNibName:@"Info"];
Would it better/clearer to allocate within the action method like this:
myPanelController = [[InfoController alloc] init];
then add this init method to my controller:
- (id)init {
self = [super initWithWindowNibName:@"Info"];
return self;
}
_______________________________________________
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.