Re: Select model objects with NSTableView using cocoa bindings
Re: Select model objects with NSTableView using cocoa bindings
- Subject: Re: Select model objects with NSTableView using cocoa bindings
- From: Quincey Morris <email@hidden>
- Date: Thu, 13 Oct 2011 15:21:42 -0700
On Oct 13, 2011, at 13:44 , Luc Van Bogaert wrote:
> Thanks, I got this working in one 'direction', ie. when the selection in the table is changed, this is reflected in my UI and the 'selected' Dot objects are drawn in a different color. For this, I decided to use a NSMutableIndexSet 'dotSelectionIndexes' property in my model object, bound to the array controller's 'selectionIndexes' binding.
… bound *from* … ;)
> But I'm afraid this still remains a little blurry on how to get the binding work in the other direction. Meaning, I would like to click a Dot object in my UI to select it, and this should change the selection in the table, resulting in turn in the Dot being redrawn with a different color.
>
> I was hoping that by just adding or replacing the contents of my 'dotSelectionIndexes' ivar (hence the choice for a NSMutableIndexSet) with the index of the clicked Dot, would trigger a selection change in the table because of the binding. It seems this doesn't work. So, obviously I'm still missing something.
So close! A simple NSMutableIndexSet property isn't KVO compliant, but the array controller bound *to* it is watching with KVO, so the thing fizzles.
Use a NSIndexSet property instead of a NSMutableIndexSet, and change the property by assigning it a new (immutable) index set -- that is, via the setter.
This means that you'll create many NSIndexSet objects at times, but unless you have vast numbers of Dot objects this is not likely to make a measurable impact on performance. If it did, it's not that hard to use a NSIndexSet property backed by a NSMutableIndexSet ivar, along with some non-standard non-KVC accessors your Dot objects would use to update the property, but you'd have to generate the requisite KVO notifications manually, and write a custom setter.
_______________________________________________
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