Re: 2 Beginner Bindings Questions
Re: 2 Beginner Bindings Questions
- Subject: Re: 2 Beginner Bindings Questions
- From: Quincey Morris <email@hidden>
- Date: Tue, 2 Nov 2010 23:49:11 -0700
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.)
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'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.
> 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.
_______________________________________________
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