• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: observeValueForKeyPath triggered twice when changing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: observeValueForKeyPath triggered twice when changing


  • Subject: Re: observeValueForKeyPath triggered twice when changing
  • From: "Smith, Steven (RSAA Storage)" <email@hidden>
  • Date: Mon, 4 Dec 2006 10:00:40 -0700
  • Thread-topic: observeValueForKeyPath triggered twice when changing


On Dec 1, 2006, at 11:01 AM, Smith, Steven (RSAA Storage) wrote:

>> I'm guessing it has to do with with "edit/commitedit" and/or
>> "change/didchange" type of messages that cause the double trigger,
but
>> I can't find anything to confirm. I thought the dictionary values of
>> "change" would have info about what is going on, but it always
returns
>> kind=1.
>
> Could you post some code?
>
>    - Scott

Below is a bit of my implemenation, for each insert(aka add),
observeValueForKeyPath
gets called four times, twice for keypath=@"arrangedObjects.amount", and
twice for @"arrangedObjects.description"


@implementation MySuperController

//+ Context string for Bindings callback routine -
observeValueForKeyPath:ofObject:change:context:

NSString *selectedColumnObservation =
@"MySuperController.selection.amount";

-(void) awakeFromNib
{
  [theArrayController addObserver:self
forKeyPath:@"arrangedObjects.amount" options:nil
context:selectedColumnObservation];
  [theArrayController addObserver:self
forKeyPath:@"arrangedObjects.description" options:nil
context:selectedColumnObservation];
}

-(void) insertObject:(id)anObject inTheTableRowsAtIndex:(uIndex)index
{
  [theTableRows insertObject:anObject atIndex:index];
}


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
NSLog(@"::::::::: START MySuperController ::::::::::::::");
NSLog(@":MySuperController keyPath=%@", keyPath);
NSLog(@":--> change=%@ context=%@", change, context);
  if (context == selectedColumnObservation)
    {
      if ([keyPath isEqualToString:@"arrangedObjects.amount"])
        {
          [self updateTally];
          [self refreshBuffer];
        }
      if ([keyPath isEqualToString:@"arrangedObjects.description"])
        {
          NSLog(@"CheckForEmpty..................");
          [self checkForEmptyDescriptionInRow:[theTableView
selectedRow]];
        }
    }
}


--- thanks, Steven
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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

  • Prev by Date: using NSPredicate to search for items with todays date.
  • Next by Date: Deciding whether text should be black or white for a given background color
  • Previous by thread: using NSPredicate to search for items with todays date.
  • Next by thread: Deciding whether text should be black or white for a given background color
  • Index(es):
    • Date
    • Thread