获取NSCollectionViewItem的NSButton的mappedObject值点击 [英] Get the representedObject values of NSCollectionViewItem NSButton click

查看:178
本文介绍了获取NSCollectionViewItem的NSButton的mappedObject值点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些问题,我发现一些很混乱,我真的不知道他们是否回答我的问题。

I have read some questions and I find some very confusing and I don't really know if they answer my question.

我有一个 NSCollectionView 实现并连接到核心数据上下文,一切正常显示。

I have an NSCollectionView implemented and connected to a Core Data context, everything shows correctly.

现在我在视图原型中有按钮,当我点击这个按钮,我需要得到的值resentObject

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.

感谢您的时间。

推荐答案

一个参数:

- (IBAction) collectionViewButtonClicked:(id)sender {
}

sender 是控件或其他UI元素

That sender is the control or other UI element (e.g., menu item) that sent the message.

有了这个参数,当你的action方法被调用时,你知道点击了哪个按钮。

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.

因此,首先,将按钮单元格的表示对象设置为拥有按钮的集合视图项目。 (您可以在nib编辑器中执行此操作。)然后,在您的操作方法中,获取按钮的单元格,然后是单元格的表示对象(它是项目),然后是项目的表示对象。

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.

如果resentObject 插件未显示在nib编辑器中,您可能已选择按钮,而不是其单元格。我建议使用左下角的按钮打开nib编辑器的大纲视图,然后从不关闭它。

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.

这篇关于获取NSCollectionViewItem的NSButton的mappedObject值点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆