我已经对NScollectionView进行了群,我正在尝试从Finder接收拖动文件。我收到的 draggingEntered: 并返回适当的价值,但我从未收到 prepareForDragOperation: (在此过程中也没有任何方法)。我这里有明显的东西吗?

代码:

- (void)awakeFromNib
{
    [self registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
}

- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
    NSLog(@"entered"); //Happens
    NSPasteboard *pboard;
    NSDragOperation sourceDragMask;

    sourceDragMask = [sender draggingSourceOperationMask];
    pboard = [sender draggingPasteboard];

    if ([[pboard types] containsObject:NSFilenamesPboardType])
    {
        NSLog(@"copy"); //Happens
        return NSDragOperationCopy;
    }

    return NSDragOperationNone;
}

- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
    NSLog(@"prepare"); //Never happens
    return YES;
}
有帮助吗?

解决方案

这很晚,但是我发现了问题:

nScollectionView默默提供了:

-(NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender

...苹果还没有记录下来。如果您简单地实现了重新启动拖动方法的方法,则一切正常,例如:

-(NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender
{
    return [self draggingEntered:sender];
}

(我是如此希望找到对这种自定义实施提供的“魔术”提供的解释,因为这也是...没有证明(谢谢,苹果!)。我猜想它可以在管理内部的插入点方面巧妙CollectionView?)。

更新:似乎特殊的魔术在NscollectionView的代表对象内。由于某种原因,Xcode4声称没有给我代表,但是分配它并运行正常。在那里查看所有自定义 /半有记录的拖放方法。

(或像我在上面描述的那样做并覆盖自定义行为,并实施有效的东西,您可以理解)

其他提示

您可能想尝试从 nScollectionViewDelegate协议

- (NSDragOperation)collectionView:(NSCollectionView *)collectionView validateDrop:(id <NSDraggingInfo> )draggingInfo proposedIndex:(NSInteger *)proposedDropIndex dropOperation:(NSCollectionViewDropOperation *)proposedDropOperation;
- (BOOL)collectionView:(NSCollectionView *)collectionView acceptDrop:(id <NSDraggingInfo> )draggingInfo index:(NSInteger)index dropOperation:(NSCollectionViewDropOperation)dropOperation;

- (BOOL)collectionView:(NSCollectionView *)collectionView canDragItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event;
- (NSImage *)collectionView:(NSCollectionView *)collectionView draggingImageForItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event offset:(NSPointPointer)dragImageOffset;
- (NSArray *)collectionView:(NSCollectionView *)collectionView namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropURL forDraggedItemsAtIndexes:(NSIndexSet *)indexes;
- (BOOL)collectionView:(NSCollectionView *)collectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard;

特别是前两种方法。

我前一段时间经历了这一点。这对我来说似乎是违反直觉的,但是我可以让它上班的唯一方法就是将关联的滚动视图设置为Drop目标。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top