当我将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;
}
他们都很好。
现在我真的想获得其他功能的拖动目标网址。 有人可以帮我解决一下吗?
答案 0 :(得分:0)
您可以尝试:
- (BOOL)collectionView:(NSCollectionView *)cv writeItemsAtIndexes:(NSIndexSet *)索引toPasteboard:(NSPasteboard *)粘贴板 {
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];
}