NSTableView 删除应用程序文件,出了什么问题?
我有以下代码来支持将应用程序文件拖放到表视图中。问题是当我拖放时我什至看不到绿色+。我认为这与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
registerForDraggedTypes
并不是在寻找文件扩展名数组;它需要一个 统一类型标识符。如果您想接受文件名,请使用 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 theNSFilenamesPboardType
:Then, to only accept
.app
files, check the extension and return YES fromtableView:acceptDrop:row:dropOperation:
, getting the appropriate information from theNSDraggingInfo
and its pasteboard.