Re: loadNibNamed:owner
Re: loadNibNamed:owner
- Subject: Re: loadNibNamed:owner
- From: Fritz Anderson <email@hidden>
- Date: Tue, 2 Mar 2010 16:45:00 -0600
On 2 Mar 2010, at 3:53 PM, David Blanton wrote:
> I have a nib file named Hoops.
> In this nib is an NSPanel.
> Outlets and Actions are defined in Files Owner and connected to the Panel.
> In code I create an object that has the corresponding Outlets / Actions as File's Owner.
> I then loadNibNamed:owner with owner as the object just created.
>
> I then crash with EXC_BAD_ACCESS ...
>
> The code:
>
> MDlgHoops* dlg = [[MDlgHoops alloc] init];
> bool ok = [NSBundle loadNibNamed:@"Hoops" owner:dlg];
> if(ok)
> [NSApp runModalForWindow:dlg->m_hoops]; // m_hoops is a panel
> else
> NSRunAlertPanel(nil, @"The Hoop Size dialog could not be displayed.", nil, nil, nil);
> [dlg->m_hoops orderOut:self];
>
> Shouldn't this just load the nib and connect the outlets / actions in File's Owner to dlg?
You don't say where it crashes, nor what you've done to investigate your problem.
Step through the code. Is "ok" YES or NO? What do the instance variables of "dlg" look like? Are they as you expect? Print the object-valued ivars to the console; are they of the type you expect? When you get the bad access, what is the stack trace?
Code smells:
* loadNibNamed:owner: (the trailing colon is part of the message's name) returns BOOL, not bool. It shouldn't matter, but precision counts in programming.
* Use of -> to access an instance variable of dlg. Better, provide an accessor ([dlg panel]) — one line in the .m, one in the .h; not a lot of trouble. Better still, provide a method that does the runModalForWindow: itself (-(int)runModal{return [NSApp runModalForWindow: m_hoops];}). Also one line in .h and .m.
* The compiler will not charge you extra if you use variable names that humans can understand.
— F
_______________________________________________
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