Matt Rajca

Jul 01 2011

AppKit Quick Tip: Highlighting an Entire NSTableView When Dragged Over

When a user drags any form of data onto a NSTableView configured as a drop destination, the data can be dropped above or on top of any row. Sometimes, it may be preferable to highlight the entire table when a drag enters its bounds, as shown below.

NSTableView Drag and Drop

To accomplish this, set your drop row to -1 in the tableView:validateDrop:proposedRow:proposedDropOperation: method, which is a part of the NSTableViewDataSource protocol.

- (NSDragOperation)tableView:(NSTableView *)tableView
                validateDrop:(id < NSDraggingInfo >)info
                 proposedRow:(NSInteger)row
       proposedDropOperation:(NSTableViewDropOperation)dropOperation {

    [tableView setDropRow:-1 dropOperation:NSTableViewDropOn];

    return NSDragOperationEvery;
}

6 notes

  1. mattrajca posted this
Page 1 of 1