Re: KeyPathsForValuesAffectingValueForKey confusion
Re: KeyPathsForValuesAffectingValueForKey confusion
- Subject: Re: KeyPathsForValuesAffectingValueForKey confusion
- From: Trygve Inda <email@hidden>
- Date: Mon, 10 May 2010 16:49:52 +0000
- Thread-topic: KeyPathsForValuesAffectingValueForKey confusion
> On May 10, 2010, at 9:12 AM, Trygve Inda wrote:
>
>> I have an NSArrayController containing items and a text field in a window
>> which is bound to a custom class "MyController" via model key path:
>> filteredResultsString
>>
>>
>> -(NSString *)filteredResultsString
>> {
>> return ([[NSNumber numberWithInt:[[itemsController arrangedObjects] count]]
>> stringValue]);
>> }
>>
>>
>> This works, except when the contents of the NSArrayController change it does
>> not update.
>>
>> If I change the binding to controller key arrngedObjects model key path
>> @count it works perfectly, but I want to use my custom method to customize
>> the output in a way that a Display Pattern can't.
>>
>> How do I get this to work?
>
> Maybe your keyPathsForValuesAffectingValueForKey is wrong. Can't say, since
> you don't show us what it is, nor anything else useful to help you in any way.
>
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"
>
The key is question is/was: filteredResultsString
I moved things around to instead use:
[self addObserver:self forKeyPath:@"itemsController.arrangedObjects.count"
options:NSKeyValueObservingOptionNew context:NULL];
and
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
// set the NSTextField
}
This seems to work fine.
_______________________________________________
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