【问题标题】:Drag and Drop in NSCollectionView example在 NSCollectionView 示例中拖放
【发布时间】:2011-01-22 18:50:32
【问题描述】:

我需要在 NSCollectionView 中拖放。

所以我查看了 Apple 的代码示例: https://developer.apple.com/library/mac/#samplecode/IconCollection/Introduction/Intro.html

有一种拖动方法。但它不起作用。

我添加了以下方法但没有结果:

-(BOOL) collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event {
    return YES;
}

委托已设置。

有人知道解决办法吗?

【问题讨论】:

    标签: cocoa nscollectionview


    【解决方案1】:

    你需要做两件事:确保你的选择在你的 NSCollectionView 中打开,并实现

    - (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard

    没有必要实现collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event,除非你想要可变的可拖动性。如果你不实现它,collection view 将尝试为 collection 中的每个 item 开始拖动。

    【讨论】:

      【解决方案2】:

      它已经在工作了。

      您必须单击,最多等待一秒钟。秒后。单击它被拖动...

      -.-

      【讨论】:

        【解决方案3】:

        您可以在集合项目视图原型中实现拖放。如果您在自己的子类中实现所需的方法,每个NSView 都支持拖动。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-07-08
          • 1970-01-01
          • 2023-03-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多