NSTableView Drag and Drop not working

I am trying to set up a very simple drag and drop for my NSTableView. There is one column in the table view (with a custom cell). The column is associated with an NSArrayController, and the array of the contents of the array controller is bound to an NSArray on my controller object. Data is displayed in the table accurately. I connected the outputs dataSourceand delegateviews of the table to my controller object, and then implemented these methods:

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard
{
    NSLog(@"dragging");
    return YES;
}

- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)op
{
    return NSDragOperationEvery;
}

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id <NSDraggingInfo>)info
              row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
{
    return YES;
}

I also registered drag and drop types in -awakeFromNib:

#define MyDragType @"MyDragType"

- (void)awakeFromNib
{
    [super awakeFromNib];
    [_myTable registerForDraggedTypes:[NSArray arrayWithObjects:MyDragType, nil]];
}

, -tableView: writeRowsWithIndexes: toPasteboard: . , , . , ? -, , ?

EDIT: . NSTextFieldCell. , ?

+3
7

. , NSCells . NSTableViewDataSource, , .

+2

, :

http://www.wooji-juice.com/blog/cocoa-10-bindings.html

, , - , , Cocoa tableView:writeRowsWithIndexes:toPasteboard .

. , , setDataSource:.

+3

initTextCell, init initImageCell ( , init). , , NSCell NSActionCell. , , .

+2

, . , ?

+1

, NSActionCell not NSCell, , . , -, NSCell, , NSActionCell . , .

0

, NStableView . 4 , - . , , .

NSButtonCell, . , , NSButtonCell NSActionCell. .

NSCell, NSActionCell, , NSActionCell.

0

. NSCell, tableView:writeRowsWithIndexes:toPasteboard, NSTableView dataSource. .

init

    self.type = NSTextCellType;

Then I get the drag and drop. If I do not, the default will be NSNullCellType, and drag and drop will not work. I assume that the people who worked it using a different subclass NSTextFieldCellwork because the cell type is different.

0
source

Source: https://habr.com/ru/post/1785104/


All Articles