FROM : Gabriele de Simone
DATE : Thu Oct 07 19:44:11 2004
On Oct 7, 2004, at 12:09 PM, Shaun Wexler wrote:
> On Oct 7, 2004, at 8:57 AM, Gabriele de Simone wrote:
>
>> Esteemed members of the Cocoa Bindings cult,
>>
>> It seems that if I add a new key to an NSArrayController and make
>> "arrangedObjects" dependent on that key, the change notifications
>> when the key is modified are never sent (or at least my views
>> dependent on "arrangedObjects" don't get updated). Here's the
>> scenario:
>>
>> + (void) initialize {
>> [self exposeBinding:@"myKey"];
>> [self setKeys:[NSArray arrayWithObjects:@"myKey", nil]
>> triggerChangeNotificationsForDependentKey:@"arrangedObjects"];
>> }
>>
>> + (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key {
>>
>> if ([key isEqualToString:@"myKey"]) {
>> return NO;
>> }
>>
>> return [super automaticallyNotifiesObserversForKey:key];
>> }
>>
>> - (void) setMyKey:(NSString*)myKey {
>>
>> if (_myKey != myKey) {
>> [self willChangeValueForKey:@"myKey"];
>> _myKey = [myKey copy];
>> [self didChangeValueForKey:@"myKey"];
>> }
>> }
>>
>> The obvious solution is to call [self rearrangeObjects] in the setter
>> method, but I am more interested in knowing whether I have
>> misunderstood/ignored some properties of NSControllers.
>
> How are you going to automatically trigger a change notification for
> that key, if you disable automatic notification for the key?!! Use
> one or the other. It's okay to send your own -rearrangeObjects
> message in the setter if you prefer. Are you just trying to avoid
> rearranging unnecessarily, if the setter is called with the same key?
> BTW, it might be better to use isEqualToString: rather than compare
> pointers, since you're making a copy.
Shaun,
I think you are misunderstanding what
automaticallyNotifiesObserversForKey: does. If you return NO, you are
just declaring the intention to call willChangeValueForKey: and
didChangeValueForKey: yourself (which is what I am doing in the
example). Even if I change my code to return YES for myKey (from
automaticallyNotifiesObserversForKey: of course), the notification for
the dependent key is not sent.
Again, the point of the question is not that I don't want to call
rearrangeObjects, but to understand why the notification is not being
triggered.
Gabe
DATE : Thu Oct 07 19:44:11 2004
On Oct 7, 2004, at 12:09 PM, Shaun Wexler wrote:
> On Oct 7, 2004, at 8:57 AM, Gabriele de Simone wrote:
>
>> Esteemed members of the Cocoa Bindings cult,
>>
>> It seems that if I add a new key to an NSArrayController and make
>> "arrangedObjects" dependent on that key, the change notifications
>> when the key is modified are never sent (or at least my views
>> dependent on "arrangedObjects" don't get updated). Here's the
>> scenario:
>>
>> + (void) initialize {
>> [self exposeBinding:@"myKey"];
>> [self setKeys:[NSArray arrayWithObjects:@"myKey", nil]
>> triggerChangeNotificationsForDependentKey:@"arrangedObjects"];
>> }
>>
>> + (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key {
>>
>> if ([key isEqualToString:@"myKey"]) {
>> return NO;
>> }
>>
>> return [super automaticallyNotifiesObserversForKey:key];
>> }
>>
>> - (void) setMyKey:(NSString*)myKey {
>>
>> if (_myKey != myKey) {
>> [self willChangeValueForKey:@"myKey"];
>> _myKey = [myKey copy];
>> [self didChangeValueForKey:@"myKey"];
>> }
>> }
>>
>> The obvious solution is to call [self rearrangeObjects] in the setter
>> method, but I am more interested in knowing whether I have
>> misunderstood/ignored some properties of NSControllers.
>
> How are you going to automatically trigger a change notification for
> that key, if you disable automatic notification for the key?!! Use
> one or the other. It's okay to send your own -rearrangeObjects
> message in the setter if you prefer. Are you just trying to avoid
> rearranging unnecessarily, if the setter is called with the same key?
> BTW, it might be better to use isEqualToString: rather than compare
> pointers, since you're making a copy.
Shaun,
I think you are misunderstanding what
automaticallyNotifiesObserversForKey: does. If you return NO, you are
just declaring the intention to call willChangeValueForKey: and
didChangeValueForKey: yourself (which is what I am doing in the
example). Even if I change my code to return YES for myKey (from
automaticallyNotifiesObserversForKey: of course), the notification for
the dependent key is not sent.
Again, the point of the question is not that I don't want to call
rearrangeObjects, but to understand why the notification is not being
triggered.
Gabe
| Related mails | Author | Date |
|---|---|---|
| Gabriele de Simone | Oct 7, 17:57 | |
| Shaun Wexler | Oct 7, 18:09 | |
| Gabriele de Simone | Oct 7, 19:44 | |
| Shaun Wexler | Oct 7, 20:45 | |
| Gabriele de Simone | Oct 7, 22:15 | |
| Jacob Lukas | Oct 8, 05:33 | |
| Steven Kramer | Oct 9, 15:46 |






Cocoa mail archive

