• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
RE: Overriding NSCollectionView's selection: a good idea?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Overriding NSCollectionView's selection: a good idea?


  • Subject: RE: Overriding NSCollectionView's selection: a good idea?
  • From: Austin Grigg <email@hidden>
  • Date: Tue, 18 Aug 2009 09:20:39 -0400

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


  • Follow-Ups:
    • Re: Overriding NSCollectionView's selection: a good idea?
      • From: Andrew McClain <email@hidden>
  • Prev by Date: Re: disabling tooltips table view
  • Next by Date: Re: int to bytes(value in NSString)
  • Previous by thread: Overriding NSCollectionView's selection: a good idea?
  • Next by thread: Re: Overriding NSCollectionView's selection: a good idea?
  • Index(es):
    • Date
    • Thread