Re: Overriding NSCollectionView's selection: a good idea?
Re: Overriding NSCollectionView's selection: a good idea?
- Subject: Re: Overriding NSCollectionView's selection: a good idea?
- From: Austin Grigg <email@hidden>
- Date: Thu, 20 Aug 2009 08:21:29 -0400
Thank you for sharing that link with me -- that is what I've been
looking for! Hopefully that will now allow me to customize my
collection views.
I believe binding the prototype view back to the NSCollectionViewItem
will give you access to the controller. As I pointed out, you should
be able to do toggle selection by just setting up the button and
outlets in IB as I described, but if you want additional
functionality, you will probably have to do what is described in the
link you sent.
Austin
On Aug 18, 2009, at 1:06 PM, Andrew McClain wrote:
Ah! So if I understand you correctly, binding my prototype view back
to the NSCollectionViewItem gives me access to each replicated
controller? I was missing that completely.
So, theoretically, I could subclass the NSCollectionViewItem, give
it a reference to my AppController, and then have the button send
an action to it, where I'd finally have access to the
representedObject property. Toggling is a fairly important property
for this case, since 90% of the time the user will be selecting
multiple objects.
FWIW, http://www.benedictcohen.co.uk/files/5b81e3c40cee2daf88ceffe6eb556a63-3.php
addresses your problem about bindings not being replicated.
Andrew
On Tue, Aug 18, 2009 at 6:20 AM, Austin Grigg
<email@hidden> wrote:
Andrew,
I would recommend using the selection that is built into the
NSCollectionView. Just make sure that "Allows Multiple Selected" is
checked in IB for your collection view and then the user can Shift-
click or Command-click or highlight with their mouse to get multiple
selection.
If the behavior you really want is to be able to click the button/
image and have it toggle the selection, you may have to create your
own implementation of an NSCollectionView. I was trying to do some
similar things and when I tried to interact with the
representedObject in my subclassed NSView I hit a brick wall. The
problem originates from the fact that the prototype view is created
once, then copied for as many items as you have in your collection,
but the bindings are not set up properly with each copy.
There is one other thing you could try, but it is not well
documented so I don't know if it will be broken in future releases.
I was able to bind the value of my disclosure button in my prototype
view in IB to the NSCollectionViewItem and set the model key path to
"selected". When the button is clicked it toggles that item's
selection. You should be able to set a different image or highlight
for each state of the button and that might do the trick for you.
The documentation for NSCollectionViewItem just doesn't mention a
selected property, it just has an isSelected and setSelected methods.
Hope that helps,
Austin
I've been reading docs and looking at IconCollection for the last
week and I
still can't really figure this out.
Here's the behavior I want to model: pretend I'm making poker dice
game (I'm
using this as an example to help me understand cocoa programming). I
have a
visual representation of the dice, and I want to select a certain
number of
them each round.
Right now I'm using NSCollectionView with a prototype view that has
a text
field (for a representation of the dice) and a button (for toggling
selection). Eventually I'll just use an image representation, but
I'm just
trying to get this to work now.
When the user clicks the button in a view, the corresponding die
will be
added into a "diceinhand" array in my AppController.
I can't figure out how, though, to connect the button in a way that
allows the AppController to understand which die has been selected
-- that is, I can't find any way to pass the representedObject
associated
with my replicated view to any controller (but perhaps I'm thinking
about
that incorrectly).
1. Can I call a selector on the representedObject itself from the
view?
Where would I set that up that programmatically (I'm assuming you
can't do
that with IB)?
or
2. Is it better to abandon the "selection buttons" and use the
selection
code of NSCollectionView? Does that mean the user needs to shift-
click to
select multiple dice? Since all I'm doing is trying to is add the
object to
another array in my AppController, couldn't I programmatically bind
the
DiceInHand array in my AppController to the selectedObjects key of
my array
controller or do I need another array controller to manage that?
I'm happy to read docs, it just seems that everything I've been
reading
deals mostly with binding values in a prototype view.
Thank you,
Andrew
_______________________________________________
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
_______________________________________________
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