I have read some questions and I find some very confusing and I don't really know if they answer my question.
I have an NSCollectionView
implemented and connected to a Core Data context
, everything shows correctly.
Now what I have is buttons
in the view prototype
, and when I click this buttons I need to get the value of the representedObject
of that cloned view.
I have read and read and some parts are confusing to me, so I'm looking for a simple explanation.
Thank you for your time.
An action method takes one argument:
- (IBAction) collectionViewButtonClicked:(id)sender {
}
That sender
is the control or other UI element (e.g., menu item) that sent the message.
With that argument, when your action method gets called, you know which button was clicked.
A button is a kind of control, and every control is backed by at least one cell. Cells have represented objects, too.
So, first, set the represented object of your button's cell to the collection view item that owns the button. (You can do this in the nib editor.) Then, in your action method, get the button's cell, then the cell's represented object (which is the item), then the item's represented object.
If the representedObject
outlet doesn't show up in the nib editor, you probably have the button selected, not its cell. I recommend opening the nib editor's outline view using the button in the lower-left and then never, ever closing it.
来源:https://stackoverflow.com/questions/15468789/get-the-representedobject-values-of-nscollectionviewitem-nsbutton-click