Get the representedObject values of NSCollectionViewItem NSButton click

为君一笑 提交于 2019-11-28 11:50:17

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!