I have implemented following delegate to support drag n drop in NSTableView. Delegates validateDrop and acceptDrop are called and I'm able to drag and drop content from Finder to NSTableView however writeRowsWithIndexes is not called when I tried to drag items from NSTableView and drop to Finder.
- (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;
}
I have registered dragging types as
//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];
Drag is not initiating in my NSTableView, Can anybody tell me what could be the possible reasons? I have custom cell in the TableView and also set delegate and datasource properly.
I found the cause, it was due to Custom cell. I had subclassed my custom cell from NSButtonCell. Dragging is not working on button cell because buttons are not meant for dragging, they are meant for illuminating. I resolved the issue by sub classing my custom cell from NSActionCell.
Found in the below post: NSTableView Drag and Drop not working
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.