Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:56:03+00:00 2026-06-02T19:56:03+00:00

I’ve got a simple, single-column, view-based NSTableView with items in it that can be

  • 0

I’ve got a simple, single-column, view-based NSTableView with items in it that can be dragged to reorder them. During drag and drop, I’d like to make it so that a gap for the item-to-be-dropped opens up at the location under the mouse. GarageBand does something like this when you drag to reorder tracks (video here: http://www.screencast.com/t/OmUVHcCNSl). As far as I can tell, there’s no built in support for this in NSTableView.

Has anyone else tried to add this behavior to NSTableView and found a good solution? I’ve thought of and tried a couple approaches without much success. My first thought was to double the height of the row under the mouse during a drag by sending -noteHeightOfRowsWithIndexesChanged: in my data source’s -tableView:validateDrop:... method, then returning twice the normal height in -tableView:heightOfRow:. Unfortunately, best I can tell, NSTableView doesn’t update its layout during drag and drop, so despite calling noteHeightOfRowsWithIndexesChanged:, the row height isn’t actually updated.

Note that I’m using a view-based NSTableView, but my rows are not so complex that I couldn’t move to a cell-based table view if doing so helped accomplish this. I’m aware of the easy, built-in ability to animate a gap for the dropped item after a drag is complete. I’m looking for a way to open a gap while the drag is in progress. Also, this is for an app to be sold in the Mac App Store, so it must not use private API.

EDIT: I’ve just filed an enhancement request with Apple requesting built in support for this behavior: http://openradar.appspot.com/12662624. Dupe if you’d like to see it too. Update: The enhancement I requested was implemented in OS X 10.9 Mavericks, and this behavior is now available using NSTableView API. See NSTableViewDraggingDestinationFeedbackStyleGap.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:56:04+00:00Added an answer on June 2, 2026 at 7:56 pm

    Note: The behavior this question and answer describes are now available using built in API in NSTableView on OS X 10.9 Mavericks and later. See NSTableViewDraggingDestinationFeedbackStyleGap.

    This answer may still be useful if this behavior is needed in an app targeting OS X 10.8 or earlier.
    Original answer below:

    I’ve implemented this now. My basic approach looks like this:

    @interface ORSGapOpeningTableView : NSTableView
    
    @property (nonatomic) NSInteger dropTargetRow;
    @property (nonatomic) CGFloat heightOfDraggedRows;
    
    @end
    
    @implementation ORSGapOpeningTableView
    
    #pragma mark - Dragging
    
    - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender
    {
        NSInteger oldDropTargetRow = self.dropTargetRow;
        NSDragOperation result = [super draggingUpdated:sender];
        CGFloat imageHeight = [[sender draggedImage] size].height;
        self.heightOfDraggedRows = imageHeight;
    
        NSMutableIndexSet *changedRows = [NSMutableIndexSet indexSet];
        if (oldDropTargetRow > 0) [changedRows addIndex:oldDropTargetRow-1];
        if (self.dropTargetRow > 0) [changedRows addIndex:self.dropTargetRow-1];
        [self noteHeightOfRowsWithIndexesChanged:changedRows];
    
        return result;
    }
    
    - (void)draggingExited:(id<NSDraggingInfo>)sender
    {
        self.dropTargetRow = -1;
        [self noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [self numberOfRows])]];
    
        [super draggingExited:sender];
    }
    
    - (void)draggingEnded:(id<NSDraggingInfo>)sender
    {
        self.dropTargetRow = -1;
        self.heightOfDraggedRows = 0.0;
        self.draggedRows = nil;
        [self noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [self numberOfRows])]];
    }
    
    - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender
    {
        self.dropTargetRow = -1;
        self.heightOfDraggedRows = 0.0;
        self.draggedRows = nil;
        [self noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [self numberOfRows])]];
    
        return [super performDragOperation:sender];
    }
    

    // In my delegate and data source:

    - (NSDragOperation)tableView:(NSTableView *)tableView validateDrop:(id<NSDraggingInfo>)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)dropOperation
    {
        if (dropOperation == NSTableViewDropOn) 
        {
            dropOperation = NSTableViewDropAbove;
            [self.tableView setDropRow:++row dropOperation:dropOperation];
        }
    
        NSDragOperation result = [self.realDataSource tableView:tableView validateDrop:info proposedRow:row proposedDropOperation:dropOperation];
        if (result != NSDragOperationNone) 
        {
            self.tableView.dropTargetRow = row;
        } 
        else 
        {
            self.tableView.dropTargetRow = -1; // Don't open a gap
        }
        return result;
    }
    
    - (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
    {
        CGFloat result = [tableView rowHeight];
    
        if (row == self.tableView.dropTargetRow - 1 && row > -1)
        {
            result += self.tableView.heightOfDraggedRows;
        }
    
        return result;
    }
    

    Note that this is simplified code, not a verbatim copy/paste from my program. I actually ended up making this all contained within an NSTableView subclass that uses proxy delegate and data source objects so the code in data source/delegate methods above is actually inside the proxies’ intercept of the calls to the real delegate and data source. That way, the real data source and delegate don’t have to do anything special to get the gap opening behavior. Also, there’s sometimes a little flakiness with the table view animations, and this doesn’t work for drags above the first row (no gap is opened since there’s no row to make taller). All in all, despite the room for further improvement, this approach works reasonably well.

    I’d still like to try a similar approach, but insert a blank row (as Caleb suggested) instead of changing the row height.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.