NSCOLLECTIONVIEWITEM 작업?
-
20-09-2019 - |
문제
사용자가 이중 클릭 할 때 조치를 설정하려면 어떻게해야합니까? NSCollectionViewItem
. NSTableView
, 예를 들어, setDoubleAction
방법. 비슷한 것이 있습니까? NSCollectionView
?
감사
해결책
당신은 아마 당신의 것을 처리하고 싶을 것입니다 NSCollectionViewItem
, NSCollectionView
그 자체 (당신의 일을 위해 NSTableView
유추).
다른 팁
나는이 질문이 고대라는 것을 알고 있지만 지금은 Google의 세 번째 결과로 나타나며 다른 곳에서는 문서화하지 않은 다르고 매우 간단한 방법을 발견했습니다. (대표 항목을 조작 할 필요는 없지만 내 앱에서 더 복잡한 작업이 있습니다.)
NSCollectionView
상속 NSView
, 당신은 단순히 사용자 정의 서브 클래스를 만들고 재정의 할 수 있습니다. mouseDown
. 이것은 함정이없는 것은 아닙니다. NSCollectionView
'에스 indexPathForItem
방법:
override func mouseDown(with theEvent: NSEvent) {
if theEvent.clickCount == 2 {
let locationInWindow = theEvent.locationInWindow
let locationInView = convert(locationInWindow, from: NSApplication.shared.mainWindow?.contentView)
if let doubleClickedItem = indexPathForItem(at: locationInView){
// handle double click - I've created a DoubleClickDelegate
// (my collectionView's delegate, but you could use notifications as well)
...
이것은 내가 Apple이 사용하려는 방법을 마침내 발견 한 것처럼 느껴집니다. 그렇지 않으면 이유가 없습니다. indexPathForItem(at:)
존재합니다.
제휴하지 않습니다 StackOverflow