NSTableView 删除应用程序文件,出了什么问题?

发布于 2024-10-14 19:43:57 字数 769 浏览 5 评论 0原文

我有以下代码来支持将应用程序文件拖放到表视图中。问题是当我拖放时我什至看不到绿色+。我认为这与 registerForDraggedTypes: 有关,但我不确定。我尝试了很多教程,但没有一个对我有用。

- (void)awakeFromNib {
[apps registerForDraggedTypes:[NSArray arrayWithObject:@"app"]];    
}


- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes         toPasteboard:(NSPasteboard*)pboard
{
return YES;
}
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
{
return NSDragOperationCopy;
}

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
          row:(int)row dropOperation:(NSTableViewDropOperation)operation
{
return YES;
}

提前致谢

I have the following code to support dropping an app file into a table view. The problem is that I don't even see the green + when I drag and drop. I think it has something to do with the registerForDraggedTypes: but I'm not sure. I've tried many tutorials and none have worked for me.

- (void)awakeFromNib {
[apps registerForDraggedTypes:[NSArray arrayWithObject:@"app"]];    
}


- (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes         toPasteboard:(NSPasteboard*)pboard
{
return YES;
}
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op
{
return NSDragOperationCopy;
}

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
          row:(int)row dropOperation:(NSTableViewDropOperation)operation
{
return YES;
}

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

触ぅ动初心 2024-10-21 19:43:57

registerForDraggedTypes 并不是在寻找文件扩展名数组;它需要一个 统一类型标识符。如果您想接受文件名,请使用 NSFilenamesPboardType :

 [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];

然后,要仅接受 .app 文件,请检查扩展名并从 tableView:acceptDrop:row 返回 YES: dropOperation:,从 NSDraggingInfo 及其粘贴板

registerForDraggedTypes isn't looking for an array of file extensions; it takes an array of uniform type identifiers. If you want to accept filenames, use the NSFilenamesPboardType:

 [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];

Then, to only accept .app files, check the extension and return YES from tableView:acceptDrop:row:dropOperation:, getting the appropriate information from the NSDraggingInfo and its pasteboard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文