我有以下代码支持将app文件放入表视图中。问题是,当我拖放时,我甚至看不到绿色+。我认为这与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;
}
提前致谢
registerForDraggedTypes
不是在寻找一系列文件扩展名;它需要一系列的uniform type identifiers。如果要接受文件名,请使用NSFilenamesPboardType
:
[self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
然后,要仅接受.app
文件,请检查扩展名并从tableView:acceptDrop:row:dropOperation:
返回YES,从NSDraggingInfo
and its pasteboard获取相应的信息。