NSCollectionView 中的拖放示例
我需要在 NSCollectionView 中进行拖放。
所以我查看了苹果的代码示例: https://developer.apple.com/library/mac/ #samplecode/IconCollection/Introduction/Intro.html
有一个拖动的方法。但这不起作用。
我添加了以下方法但没有结果:
-(BOOL) collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event {
return YES;
}
委托已设置。
有人知道解决办法吗?
I need drag and drop in NSCollectionView.
So I looked at Apples code-sample:
https://developer.apple.com/library/mac/#samplecode/IconCollection/Introduction/Intro.html
There is a method for dragging. But it's not working.
I added the following method without result:
-(BOOL) collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event {
return YES;
}
The Delegate is set.
Does anybody know a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要做两件事:确保您的选择在 NSCollectionView 中打开,并实现
- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard
没有必要实现
collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event
除非你想要可变的可拖动性。如果您不实现它,集合视图将尝试为集合中的每个项目启动拖动。You need to do two things: make sure your selection is turned on in your NSCollectionView, and implement
- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard
It's not necessary to implement
collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event
unless you want variable draggability. If you don't implement it, the collection view will attempt to start a drag for every item in the collection.它已经开始工作了。
您必须单击,最多等待一秒钟。秒后。单击它会被拖动...
-.-
It is already working.
You will have to click, wait up to one sec. After the sec. clicking it is dragged...
-.-
您只需实施拖放即可放入集合项视图原型中。如果您在自己的子类中实现所需的方法,则每个 NSView 都支持拖动。
You can just implement drag & drop in the collection item view prototype. Every
NSView
supports dragging if you implement the required methods in your own subclass.