Re: Custom sheet question - which variable?
Re: Custom sheet question - which variable?
- Subject: Re: Custom sheet question - which variable?
- From: Roland King <email@hidden>
- Date: Mon, 11 Jan 2010 21:07:19 +0800
On 11-Jan-2010, at 4:53 PM, Jenny M wrote:
> Oooh... okay, that helps... I haven't loaded yet, so I'm not sure what to put in it. In the MyObject XIB file, I manually set File's Owner to be the custom NSWindowController subclass, not AppDelegate. But, I'm trying to open the sheet from the AppDelegate class. Is that possible?
>
You can do whichever you like. I tend to wander objects up and down my various controller and delegate chains as I write code because where I think I want it, I sometimes don't want it. Ask yourself this, what is this sheet most closely tied to? Is it something which is going to be used in the delegate on some kind of delegate callback? If so, you probably want the delegate to own it. Or is it something the WindowController really wants to 'own'? If that's the case then let it own it.
If (in the code you posted) you're at that point in your AppDelegate then 'self', the thing you pass as owner, is the wrong type for the way you say you have your XIB configured. You need to make sure that the 'owner' is an object of the class you've told the XIB that File's Owner is; it can be what you like, but you have to be consistent. If you want it to be in your NSWindowController subclass, then for 'owner' you need to pass that window controller subclass object and the window you require will end up bound to some properly (you define) of that, then you pass [ yourWindowController thePropertyYouChose ] as the window to your sheet method.
And don't forget, in your XIB .. you need to make the connection to the property in File's Owner. Oh yes it's easily said but so easily overlooked and you'll be asking why your sheet doesn't come up after you loaded the NIB and it will be because the outlet is nil because you didn't actually hook it up graphically in IB.
> It's possible I shouldn't separate this, at least to do what I want to be able to do with sheet.s In the books I've read, that's the way they've set up objects and controllers for MVC... I'm still learning, I'm in the middle (somewhere, on and off) of Hillegass and Anderson's books, but they don't answer everything. :) Thanks for the help here, guys, much appreciated.
>
>
> On Mon, Jan 11, 2010 at 12:37 AM, Roland King <email@hidden> wrote:
>
>
> In your [ NSBundle loadNibNamed .. ] what's 'self' the owner you've given it, is that your AppDelegate subclass? That's how you hook this up.
>
> In IB you have 'Files Owner' which is going to be whatever object you pass into the loadNibNamed call. So add an outlet to that (IBOutlet property of type NSWindow* or similar called whatever makes sense to you), then hook up the window in your XIB to that property of File's Owner.
>
> Now the window is in [ self whateverPropertyYouCalledIt ] after the NIB has loaded.
>
_______________________________________________
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