开发者

NSCollectionView get selected item on button click

I have a NSCollectionView is bound to an NSArrayController that has an NSMutableArray as content. Items in the NSMutableArray are displayed as they should.

I have an WindowController class that holds a reference to the NSMutableArray. There is also a button that causes a buttonClicked message to be sent to my WindowController.

Now inside buttonClicked I want to know what item is selected in the NSCollectionView. How do I do this? I have no reference to the NSArrayController otherwise I could have asked it by sending selection. I've studied some sample code but to no avail.

How can I get a referenc开发者_如何学运维e to the currently selected item in the NSArrayController?


if the NSCollectionView is getting its content from the NSArrayController, as there is a binding set in IB on content or you have programmatically bound these, there is also a binding available on the collectionView's selectionIndexes, which when bound to the arrayController will give you 'a reference to the currently selected item' in the arrayController and the collectionView.

NSCollectionView's itemAtIndex, handed the currently selected item's index, will get you the actual item that is selected.

is the actual item that is selected what you are looking to obtain a reference to?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜