获取在NSCollectionView中点击按钮的视图的索引 [英] Get the index of view from which a button was clicked in a NSCollectionView

查看:342
本文介绍了获取在NSCollectionView中点击按钮的视图的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSCollectionView ,我添加了我的自定义视图作为 NSCollectionViewItem 为该集合视图。在我的collectionViewItem中,我有一个 NSButton 以及各种其他元素。我有一个方法 onButtonClick 它连接到那个按钮。现在,假设我将我的collectonViewItem的5个项目添加到collectionView。
如何获取点击按钮的视图的索引?

I have a NSCollectionView and I am adding my custom view which acts as NSCollectionViewItem for that collection view. In my collectionViewItem, I have a NSButton along with various other elements. I have a method onButtonClick which is connected to that button. Now, suppose I add 5 items of my collectonViewItem on to the collectionView. How can I get the index of the view from where the button was clicked?

内部 onButtonClick ,我尝试下面的代码,但它总是返回0无论哪个按钮我点击:

Inside onButtonClick, I tried following code but it always returns 0 regardless of which button I click:

id collectionViewItem = [sender superView];
NSInteger index = [[colloectionView subviews]  indexOfObject:collectionViewItem];

这是什么正确的方法?

推荐答案

你不能通过单击一个控件(它有自己的functon)返回索引.i认为你必须看到 http://andrehoffmann.wordpress.com/2009/08/29/nscollectionview-tutorial-for -dummies-xcode-3-1-3 /
之前,检查collectionview选择在属性检查器中可选(也可以通过禁用按钮尝试)

you cant return index by clicking a control (which having its own functon).i think you have to see http://andrehoffmann.wordpress.com/2009/08/29/nscollectionview-tutorial-for-dummies-xcode-3-1-3/. before that check collectionview selection as selectable in attributes inspector.(and also try by disable the button)

这篇关于获取在NSCollectionView中点击按钮的视图的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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