On 03/11/2010, at 5:49 PM, Quincey Morris wrote:

> On Nov 2, 2010, at 23:08, Peter Zegelin wrote:
> 
>> I am having great difficulty showing the same selection of items using 
>> bindings. I would basically like to select rows in one table and have the 
>> selection updated in the other.
>> 
>> Pretty well everything I have tried either causes an exception or does 
>> nothing.
>> 
>> In the TableView I have tried binding the SelectionIndexes using various 
>> combinations of the selection based Controller Keys with various Model Key 
>> Paths ( including none ).
>> I have also done some things with the Selection Indexes in the 
>> ArrayController bindings as well.
>> 
>> So my question is - just what combination is required to get this to work?
> 
> Some single object -- I'll get back to the question of which one -- should 
> have a property named something like "selectionIndexes". Bind the 
> "selectionIndexes" binding of the array controllers to this property. That's 
> all you should have to do. (It isn't normally necessary to bind in IB the 
> table view's "selectionIndexes" binding to the array controller, because this 
> happens automatically by default.)

        OK That makes sense. I was so focused on trying to get it to work that 
I forgot there is a shared array but 2 instances of the arrayController. 
Selection being the property of the table makes it obvious that 
my efforts would never work. I need a way to share the selection indexes as 
well.  UPDATE: This works!!
> 
> So which object should have this "selectionIndexes" property that's shared by 
> the views? The easiest way is to put it in your data model object -- 
> presumably the same one that has the array property. This would make perfect 
> sense, for example, if your application is document based and you actually 
> wanted to save the selection in the document file.
> 
> However, if the selection is just an attribute of the user interface, it 
> doesn't really belong in the data model. If the two table views are 
> necessarily in the same window, you could put the property in the window 
> controller. Otherwise, the property will need to be in some auxiliary 
> singleton object. I think in this case you could just use a dictionary with a 
> "selectionIndexes" key, or you could create a custom singleton object (which 
> would be a "C" in the MVC paradigm). The File's Owner object(s) of the NIB(s) 
> would then have a property whose value is this singleton, so that you can 
> bind to it. Or, if there are 2 window controller classes, you could put it in 
> one window controller and derive an identical property in the other window 
> controller.

I'll store it where the array is stored. My model is actually C++ so I already 
have an object that gets passed to each new view as it is created so it can 
access the model, and I already have other stuff there that doesn't really 
belong with the model or is in Obj-C.
> 
> I'm not sure I'm making sense in this description. It's harder to say than to 
> do.
> 
> Actually, you can probably just bind the "selectionIndexes" binding of one 
> array controller to the "selectionIndexes" property of the other. I can't 
> quite think that through, but it may be that simple.

Yeah I don't think that's possible - certainly not in IB. Its two or more 
instances of the same arrayController and they could be in different windows 
when they wake up.
> 
>> My array is very simple with just some strings added. The tableviews are 
>> single column with description for the identifier and the table column is 
>> bound using arrangedObjects as the Controller Key and 
>> description as the Model Key Path
>> 
>> My other question is related. I would like to enable the delete button only 
>> if there is a selection in the table. Again, I have tried binding the 
>> enabled property of the button to the controller with various combinations 
>> of Controller Key and Model Key Path, with no luck.
> 
> Bind the enable state of the button to the "canRemove" property of the array 
> controller. Note that it's actually inherited from the superclass, 
> NSObjectController, which is probably why you didn't find it.
> 
> 

Tried that and it didn't work. The button never disables/enables with the 
selection and pressing it removes the first object in the array even if not 
selected. When the last object is removed *then* the button disables.

Thanks for your help!

kind regards,

Peter Zegelin
http://www.fracturedsoftware.com
Rondo - MIDI for your mac
MacSimAVR - AVR microcontroller simulator for OS X

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to