【发布时间】:2014-09-09 12:27:05
【问题描述】:
我已经实现了以下委托以支持在 NSTableView 中拖放。调用了委托 validateDrop 和 acceptDrop,我可以将内容从 Finder 拖放到 NSTableView,但是当我尝试将项目从 NSTableView 拖放到 Finder 时,不会调用 writeRowsWithIndexes。
- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
NSLog(@"writeRowsWithIndexes");
return YES;
}
- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation
{
NSLog(@"validateDrop");
return NSDragOperationCopy;
}
- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id < NSDraggingInfo >)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
{
NSLog(@"acceptDrop");
return YES;
}
我已将拖动类型注册为
//Registering dragged Types
[tableView registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
//To support across application passing NO
[tableView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
//Don't want any highlight selection on drop
[tableView setDraggingDestinationFeedbackStyle:NSTableViewDraggingDestinationFeedbackStyleNone];
在我的 NSTableView 中没有启动拖动,谁能告诉我可能的原因是什么?我在 TableView 中有自定义单元格,并且还正确设置了委托和数据源。
【问题讨论】:
-
1.在命中和试验中,我发现拖动只是从单元格分隔符开始,而不是在单元格内容区域。 2.拖拽图片delegate也不叫——(NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent *)dragEvent offset:(NSPointPointer)dragImageOffset
标签: objective-c macos cocoa nstableview