1

我正在开发一个在将 NSCollectionViewItem 拖到 Finder 时将文件复制到 Finder 的函数,因此我实现了以下委托:

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

    NSMutableArray *urls = [NSMutableArray array];
    [indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop)
     {
         NSDictionary *dictionary = [[cv content] objectAtIndex:idx];
         [urls addObject:[dictionary objectForKey:KEY_URL]];
     }];

    if ([urls count] > 0)
    {
        [pasteboard clearContents];
        BOOL result = [pasteboard writeObjects:urls];
        return result;
    }
    return NO;
}

或者这样:

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

    NSMutableArray *urls = [NSMutableArray array];
    [indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop)
     {
         NSDictionary *dictionary = [[cv content] objectAtIndex:idx];
         [urls addObject:[[dictionary objectForKey:KEY_URL] path]];
     }];

    [pasteboard declareTypes:@[NSFilenamesPboardType] owner:self];
    [pasteboard setPropertyList:urls forType:NSFilenamesPboardType];

    return YES;
}

他们都工作正常。

现在我真的很想获取其他功能的拖动目标网址。任何人都可以帮我解决它吗?

4

1 回答 1

0

你可以试试:

-(BOOL)collectionView:(NSCollectionView *)cv writeItemsAtIndexes:(NSIndexSet *)索引到Pasteboard:(NSPasteboard *)pasteboard {

NSMutableArray *urls = [NSMutableArray array];
[indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop)
 {
     NSDictionary *dictionary = [[cv content] objectAtIndex:idx];
     [urls addObject:[[dictionary objectForKey:KEY_URL] path]];
 }];

[pasteboard clearContents];

return [pasteboard writeObjects:urls];

}

于 2013-05-28T09:47:45.040 回答