Re: bindings via file's owner don't update
Re: bindings via file's owner don't update
- Subject: Re: bindings via file's owner don't update
- From: Mikkel Eide Eriksen <email@hidden>
- Date: Mon, 29 Nov 2010 18:00:14 +0100
I just tried properly adding the loadingWindowController to NSDocument's windowControllers without any luck. Then I tried moving the @property objectCount to my loadingWindowController and updating it from NSDocument:
[[self loadingWindowController] setObjectCount:[[self loadingWindowController] objectCount]+1];
Still no go on the interface (I can tell via logs that controller.objectCount is incrementing as it should), though the NSTextField is now bound directly to file's owner.objectCount instead of owner.document.objectCount...
Regards,
Mikkel
On Nov 29, 2010, at 5:10 PM, Mikkel Eide Eriksen wrote:
> I don't think I'm "replacing" the document per se. In my NSDocument init override, I do this (only relevant parts copied):
>
> if (![self loadingWindowController])
> [self setLoadingWindowController:[[MyLoadingWindowController alloc] init]];
> [[self loadingWindowController] setDocument:self];
>
> MyLoadingWindowController currently only has its init method overridden:
>
> -(id)init
> {
> if (![super initWithWindowNibName:@"Loading"])
> return nil;
>
> return self;
> }
>
> I guess I could even just not use my own NSWindowController subclass and just call initWithWindowNibName directly in my NSDocument init and get the same effect.
>
> Reading up on the documentation, I guess what I should do in my Document init is this:
>
> if (![self loadingWindowController])
> [self setLoadingWindowController:[[MyLoadingWindowController alloc] init]];
> [self addWindowController:loadingWindowController];
>
> I'll test that out today.
>
> Regards,
> Mikkel
>
> James Bucanek wrote:
>>> Basically, if I add an observer using the path "document.someProperty", KVO
>>> attaches the observer to the the someProperty object, not document. So if I
>>> change it (document.someProperty = newProperty), newProperty replaces the
>>> original object, which is then released. newProprety doesn't have any
>>> observers and doesn't post any notifications when its properties change.
>>
>> Boy, I totally hosed that description.
>>
>> What I meant to say is, if you're observing a property of a property (controller.document.prop) the observer for the property is attached to document object, not the controller object. So if you replace the document object in the controller (controller.document = newDocument), the binding in the old document gets lost and changes to the new document.prop won't be observed.
>>
>> --
>> James Bucanek
>
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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