gpt4 book ai didi

objective-c - 当我将 NSCollectionView 中的项目拖动到 Finder 时如何获取拖动目标 url

转载 作者:行者123 更新时间:2023-12-03 17:22:52 24 4
gpt4 key购买 nike

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

- (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;
}

两者都工作正常。

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

最佳答案

你可以尝试:

-(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];

}

关于objective-c - 当我将 NSCollectionView 中的项目拖动到 Finder 时如何获取拖动目标 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16704644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com