Re: bindings and sub array modification notification.
Re: bindings and sub array modification notification.
- Subject: Re: bindings and sub array modification notification.
- From: Quincey Morris <email@hidden>
- Date: Sun, 18 Jan 2009 15:25:42 -0800
On Jan 18, 2009, at 14:13, Sandro Noel wrote:
My model is like this.
Host (custom class).
NSString *hostName
NSArray *informationElements.
In interface builder I have the host collection view bound to an
array controller (arangedObjects.)
who itself is bound to the :hosts: array of my window controller
and the information collection view is bound to and array controller
who is bound to the host Array Controller as (Selection)
Are you saying that the "information collection view" is a
NSCollectionView which displays a subview for each information element
in the currently selected host?
This works just fine.
The problem I am having is this, when I add a host to the array
controller, the view get's updated with the new values.
but when i add information to an already existing host, the
information is there but it does not get displayed until
the selection changes and comes back to that element.
Are you saying that the "information collection view" fails to show an
additional subview when a new information element is added, or that an
existing subview fails to update when its information is changed, or
something else?
I've tried to use
from the add window controller. witch is not where the hosts
variable is declared.
What is an "add window controller"? If you mean it's the window
controller that has some "add" button's action method, it's irrelevant
-- it doesn't matter what *makes* the change, but what the change is
*made to* (and how).
There are basically two routes to changing an array that has a
NSArrayController bound to it:
1. Change the data model directly. Logically, this would be
[informationElements addObject: ...] (or some similar thing), but that
is not KVO-compliant, so you must instead write [[host
mutableArrayValueForKey: @"informationElements"] addObject: ...].
2. Use one of the NSArrayController methods such as add: or
addObject:, which will update your data model KVO-compliantly for you.
[self willChangeValueForKey:@"informationElements"];
[self didChangeValueForKey:@"informationElements"];
[hosts willChangeValueForKey:@"informationElements"];
[hosts didChangeValueForKey:@"informationElements"];
[self willChangeValueForKey:@"hosts.informationElements"];
[self didChangeValueForKey:@"hosts.informationElements"];
Using willChange/didChange with no actual change in between is failure-
prone, because willChange assumes that the value hasn't changed yet.
It sometimes works but it's a kind of abuse, and probably suggests a
wrong decision elsewhere (e.g. failing to use option 1 or option 2).
nothing happens.
I'm not using the InformationArraycontroller because
I am not sure of current selection when the information is saved.
So option 2 is not feasible here. Use option 1 instead.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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