Get the index of view from which a button was clicked in a NSCollectionView

人盡茶涼 提交于 2020-01-06 07:16:50

问题


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?

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];

What is the right way to achieve this?


回答1:


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)



来源:https://stackoverflow.com/questions/12814028/get-the-index-of-view-from-which-a-button-was-clicked-in-a-nscollectionview

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