Re: Modifying the array of an NSArrayController
Re: Modifying the array of an NSArrayController
- Subject: Re: Modifying the array of an NSArrayController
- From: René Puls <email@hidden>
- Date: Fri, 7 Nov 2003 11:16:54 +0100
Hi all,
I just tried adding the (will|did)ChangeValueForKey: notifications as
suggested by Henrik, and it solved my problem:
[self willChangeValueForKey:@"array"];
[array addObject:[NSDictionary dictionaryWithObject:@"New Item"
forKey:@"string"]];
[self didChangeValueForKey:@"array"];
Seems like this is a basic misunderstanding of how key-value observing
works.
Apparently the "owner" of the array--not the array itself--is
responsible for notifying observers when new objects are added. Also,
observers don't register with the array for changes, they register with
the owner. The array will only notify me of changes to *specific*
objects that it contains.
Subclassing NSArrayController and overriding newObject to initialize
new objects seems rather complicated to me. I think Aaron Hillegass is
right with his suggestion to add some delegate methods like
arrayController:willAddNewObject: to NSArrayController.
http://cocoa.mamasam.com/COCOADEV/2003/11/1/76257.php
Anyway, I think I can work with this for now. Thanks everyone for your
help!
I have one more question concerning KVO though. The documentation says
this about automatic change notifications:
http://developer.apple.com/documentation/Cocoa/Conceptual/
KeyValueObserving/Concepts/AutoVsManual.html
Automatic key-value observing informs observers of all changes made
through key-value compliant methods, the key-value coding methods, as
well as directly assigning a value to an instance variable. The
examples shown in Listing 3-1 result in any observers of the property
name to be notified of the change.
From the examples:
// assigning an instance variable directly
name=[newSavingsName retain];
How can the run-time system notice a change to the actual instance
variable? Isn't this just like accessing a memory location? I thought
this was only possible using some kind of debugging technique, like a
breakpoint?
Kind regards,
Rene Puls
_______________________________________________
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.