2

我有以下代码来支持将应用程序文件拖放到表格视图中。问题是当我拖放时我什至看不到绿色+。我认为这与它有关,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;
}

提前致谢

4

1 回答 1

2

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

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

然后,要只接受.app文件,请检查扩展名并从中返回 YES ,从及其粘贴板tableView:acceptDrop:row:dropOperation:中获取适当的信息。NSDraggingInfo

于 2011-01-29T21:41:43.680 回答