Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
456 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...