Matt Rajca

blog projects github twitter email

AppKit Quick Tip: Highlighting an Entire NSTableView When Dragged Over

July 16, 2011

When data is dragged onto a NSTableView configured as a drop destination, it can be dropped above or on top of a 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;
    }