Re: Getting added object with KVO
Re: Getting added object with KVO
- Subject: Re: Getting added object with KVO
- From: Hannes Petri <email@hidden>
- Date: Mon, 17 Jul 2006 11:19:38 +0200
On 17 jul 2006, at 11:18, Hannes Petri wrote:
Hello, I'm here again. After some responses, it was rather clear
that what I tried to do isn't working. But I haven't given up yet,
and now the problem is a little different.
I've found this message:
http://www.cocoabuilder.com/archive/message/cocoa/2004/12/1/122701
I've created a wrapper around the array that i call
CollectionsManager. This is the source code for it:
- (id)init
{
if (self = [super init])
{
collections = [[NSMutableArray alloc] init];
return self;
}
return nil;
}
- (void)insertObject:(id)object inCollectionsAtIndex:(int)index
{
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:
[NSIndexSet indexSetWithIndex:index] forKey:@"collections"];
[collections insertObject:object atIndex:index];
[self didChange:NSKeyValueChangeInsertion valuesAtIndexes:
[NSIndexSet indexSetWithIndex:index] forKey:@"collections"];
}
- (void)removeObjectFromCollectionsAtIndex:(int)index
{
[self willChange:NSKeyValueChangeRemoval valuesAtIndexes:
[NSIndexSet indexSetWithIndex:index] forKey:@"collections"];
[collections removeObjectAtIndex:index];
[self didChange:NSKeyValueChangeRemoval valuesAtIndexes:
[NSIndexSet indexSetWithIndex:index] forKey:@"collections"];
}
- (NSMutableArray *)collections
{
return collections;
}
- (int)countOfCollections
{
return [collections count];
}
- (CCICollection *)objectInCollectionsAtIndex:(int)index
{
return [collections objectAtIndex:index];
}
As you can see, it implements the indexed accessors methods. I
observe it like this:
[collectionsManager addObserver:collectionsView
forKeyPath:@"collections"
options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld
context:NULL];
The thread says that what I wanted from the beginning (see original
message below) should work by doing this way. But it don't. What am
I doing wrong this time? I've tried a lot now, but i cant find the
solution.
I would be very, very grateful if someone could help me.
Hannes Petri
email@hidden
Hello!
I'm using KVO to observe an array controller, and when an object
is added, a view should be changed.
Now I want a pointer to the object that was added. How should I do?
Apples documentation says that I should get the index of the new
object, by querying the changes-dict with the key
NSKeyValueChangeIndexesKey, but that returns null.
What am I doing wrong? Is it possible to achieve what I want?
Hannes Petri
email@hidden_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden