Re: Showing a NSPanel
Re: Showing a NSPanel
- Subject: Re: Showing a NSPanel
- From: email@hidden
- Date: Thu, 2 Dec 2010 19:49:55 -0700
Thanks for your reply.
The reason it was exploding was an error in a class assigned to a
control in the panel. It all works fine now as:
About *about = [[[About alloc] init] autorelease];
BOOL ok = [NSBundle loadNibNamed:@"About" owner:about];
if(ok)
{
[NSApp runModalForWindow:about->m_panel];
[about->m_panel orderOut:self];
}
-koko
On Dec 1, 2010, at 5:31 PM, Laurent Daudelin wrote:
On Dec 1, 2010, at 15:43, email@hidden wrote:
The code below explodes on the loadNibNamed call but I have done
this many times ... where am I wrong?
@interface About : NSPanel {
}
- (IBAction)about:(id)sender {
About *aboutpanel = [[About alloc] init];
[aboutpanel retain];
BOOL ok = [NSBundle loadNibNamed:@"About" owner:aboutpanel];
if(ok)
{
[NSApp runModalForWindow:aboutpanel];
}
}
any help appreciated …
Hmmm… haven't you read the basic documentation about memory
management in Objective-C? What about NSWindow and NSPanel?
There are many things wrong in the little excerpt of code you
provided. You first create a new instance of your NSPanel's subclass
"About" without using one of 2 recommended initializers for
NSWindow. After doing your alloc/init, you even put a "retain" that
is totally unnecessary. By doing alloc/init, you already "own"
aboutpanel, there is no need to retain it. That tells me, sorry to
say this, that you're missing some basic concepts of Objective-C.
Finally, although I guess that, in theory, you can have an instance
of NSPanel as the owner of a nib, I've never seen anything like it
in the 15 years I've been programming in Objective-C. Usually, the
nib is owned by some controller object, which manages the interface
(view) with the data (model) driving the view.
So, I think you should get a good book about the fundamentals of
Objective-C and Cocoa and start reading. I'm not even sure where to
start to help!
You just can't slap a few methods here and there without thinking
about what you're doing, sorry. It doesn't work that way.
-Laurent.
--
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin http://www.nemesys-soft.com/
Logiciels Nemesys Software email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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