Search code examples
objective-cdrag-and-dropnstableviewnsdragginginfo

Can NSTableView handle normal drag-and-drop methods?


I'd like to use NSTableView without the NSTableViewDataSource Methods but just like a normal view. draggingEntered: and draggingExited: are being called but when I return NSDragOperationCopy, I don't see the green plus mouse pointer and performDragOperation: doesn't get called.

I subclassed the NSTableView with these methods:

- (void)awakeFromNib
{
    [self registerForDraggedTypes: [NSArray arrayWithObject: NSFilenamesPboardType]];
}

- (NSDragOperation)draggingEntered: (id < NSDraggingInfo >)sender
{
    NSLog(@"draggingEntered"); //Gets called
    return NSDragOperationCopy;
}

- (void)draggingExited: (id < NSDraggingInfo >)sender
{
    NSLog(@"draggingExited"); //Gets called
}

- (BOOL)performDragOperation: (id < NSDraggingInfo >)sender
{
    NSLog(@"performDragOperation"); //Doesn't get called
    return YES;
}

Solution

  • The documentation says it conforms to the NSDraggingDestination and NSDraggingSource protocol, so yes it should hand normal drag-and-drop.

    You might try using -registerForDraggedTypes: method from nsview.