• 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: key value observing stops
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: key value observing stops


  • Subject: Re: key value observing stops
  • From: Francisco Tolmasky <email@hidden>
  • Date: Tue, 24 Feb 2004 07:50:40 -0800

Ok, here it is, it's a little contrived:

NSString * const WellKnownKey= @"well known";

@implementation modelClass

- (void)setObject:(id)anObject forKey:(NSString *)aKey
{
[self willChangeValueForKey: aKey];
[internalMutableDictionary setObject: anObject forKey: aKey];
[self didChangeValueForKey: aKey];
}

@end

@implementation textViewSubclass

- (void)didChangeText
{
//...
[model setObject: [[self string] substringWithRange: aCalculatedRange]
forKey: WllKnownKey];
}

@end

@implementation TableViewSubclass

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context
{
[self setNeedsDisplay: YES];
}

@end

//.. in window controller
- (void)awakFromNib
{
[arrayController
addObserver: tableview
forKeyPath:[NSString stringWithFormat: @"selection.%@", WellKnownKey]
options: (NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
context: NULL];
}

The array controller holds instances of my modelClass. I have a custom
NSCell being used by my table view subclass and all I want to happen is
that whenever the text field changes the model, for the cell to update
to show changes. I tried having the cell observe the values and that
worked but since table view does a lot of weird adding and removing of
cells it kept crashing when i tried to remove the observer. Does this
help in determining what's wrong?

Francisco Tolmasky
email@hidden
http://users.adelphia.net/~ftolmasky
On Feb 24, 2004, at 12:56 AM, Allan Odgaard wrote:

> On 24. Feb 2004, at 9:01, Francisco Tolmasky wrote:
>
>> For some reason my key value observing stops after successive calls.
>> [...]
>
> Since KVO is not based on fuzzy logic, the problem is most likely that
> you do something wrong elsewhere -- so it would be useful if you
> posted your code.
>
> Though one problem could be that you are setting the same value. E.g.
>
> [obj2 bind:@"Something" toObject:obj1 withKeyPath:@"Something"
> options:nil];
> [obj1 setSomething:foo]; // will also set in obj2
> [obj1 setSomething:foo]; // will skip "notification"
>
> It might be more indirect, e.g. if you set an array, make changes to
> that array and set it again, it will not be considered a new value (if
> the setter only retains the array).
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: key value observing stops
      • From: Allan Odgaard <email@hidden>
References: 
 >key value observing stops (From: Francisco Tolmasky <email@hidden>)
 >Re: key value observing stops (From: Allan Odgaard <email@hidden>)

  • Prev by Date: Alternating row colors in a table view?
  • Next by Date: Re: Alternating row colors in a table view?
  • Previous by thread: Re: key value observing stops
  • Next by thread: Re: key value observing stops
  • Index(es):
    • Date
    • Thread