我正在开发一个在将 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;
}
他们都工作正常。
现在我真的很想获取其他功能的拖动目标网址。任何人都可以帮我解决它吗?