Tracking an NSArrayController's selection
Tracking an NSArrayController's selection
- Subject: Tracking an NSArrayController's selection
- From: Camillo Lugaresi <email@hidden>
- Date: Wed, 28 Dec 2005 13:00:34 +0100
I have a two-tiered hierarchy of objects and master-detail interface.
An NSTableView displays objects in the first tier, another
NSTableView displays the children of the selected first-tier object,
and other controls display properties for the selected first-tier and
second-tier objects. Each NSTableView is bound to an NSArrayController.
Each first-tier object needs to keep track of which one of its
children is selected, and save its index into a variable. The master
controller needs to do the same for the index of the selected first-
tier object. This is required by the application's back-end
interface, which I cannot change.
I tried to implement this by binding each NSArrayController's
selectionIndexes property to a key in the appropriate object, whose
accessors convert between arranged indexes and content indexes.
This method works fine for the first-tier objects, but fails for the
second tier. When I change the first-tier selection, the newly
selected object receives a message to set its selection indexes
(which should track the selected child of that object) to 0. After
that, it is queried twice for the current selection, but it is always
zero at this point. So, while the second-tier selection is saved
correctly, it is always automatically cleared when it is time to
reuse it. Changing the second-tier NSArrayController's "preserves
selection" option has no effect on this behavior.
If it helps visualize the problem, here is a log of the messages
received by first-tier objects when the second-tier selection changes:
set <currentFirstTierObject> selected child: 0 -> 3
get <currentFirstTierObject> selected child: 3
and when the first-tier selection changes:
set <newlySelectedFirstTierObject> selected child: 5 -> 0
get <newlySelectedFirstTierObject> selected child: 0
get <newlySelectedFirstTierObject> selected child: 0
I guess I could simply set a delegate on the NSTableViews and track
the selection using tableViewSelectionDidChange, but since the rest
of the interface is completely based on bindings, that would look
like an ugly asymmetry. Any suggestions on how to implement this
properly using bindings?
Camillo
_______________________________________________
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