Subject: Re: Accessing NSWIndowController attribute from a
subview in IB




Am 28.04.2011 um 13:28 schrieb Ben Golding:

> I have a document-based app which loads a couple of NSWindowController
> subclasses. That's fine. In one of the subclasses, I load a nib with a
> NSView subclass. It wants to access one of the instance vars in the window
> controller subclass. I thought "no worries, I should be able to hook up a
> connection in IB and it will be right".

You can not connect to an ivar/attribute of an object. You can just connect to
an object.

> In my NSWindowController subclass (called "Face"), I have a method:
>
> - (id)initWithSundial:(Sundial *)sundial
> {
> if ((self = [super initWithWindowNibName:@"Face"]) == nil)
> return nil;
>
> [self setSundial:sundial];
>
> return self;
> }
>
> In the window that's loaded from Face.xib, there's a custom view
> (SundialView) which needs to access the sundial instance variable in File's
> Owner. I just don't seem to be able to control-drag in some order to hook
> them up and I think I should be able to.
>
> Am I doing this the wrong way or do I have some sort of misunderstanding
> about how this works?

Either or both.

The view itself should not know anything about its controller or the
controllers ivars. Wrong direction.
You should make your WindowController set SundialView's sundial when it has
been loaded. Problem solved.

atze_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)

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:
http://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to maillists@xxxxxxxxx



Privacy