One Quickie


Table View drag destination on or between rows (NSTableView->General)
When your NSTableView is a drag destination, you may want to support both dragging onto existing objects (to replace them, or augment them with some new attribute the user is dragging over) and support dragging between existing objects (to insert a new one in between. To get this behavior, you need to use NSTableView's -setDropRow:dropOperation:, like so:
- (NSDragOperation) tableView: (NSTableView *) view
                 validateDrop: (id ) info
                  proposedRow: (int) row
        proposedDropOperation: (NSTableViewDropOperation) op
{
    // have the table highlight on-row / between-row correctly
    [view setDropRow: row
          dropOperation: op];

    // or use whatever drag operation is appropriate
    NSDragOperation dragOp = NSDragOperationCopy;

    return (dragOp);

} // validateDrop
and in the acceptDrop method, look at the operation:
- (BOOL) tableView: (NSTableView *) view
        acceptDrop: (id ) info
               row: (int) row
     dropOperation: (NSTableViewDropOperation) op
{
    if (op == NSTableViewDropOn) {
        // replace existing

    } else if (op == NSTableViewDropAbove) {
        // add new

    } else {
        NSLog (@"unexpected operation (%d) in %s",
               op, __FUNCTION__);
    }

    // documentation doesn't actually say what this signifies
    return (YES);

} // acceptDrop



borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book

webmonster@borkware.com