title: NSView based NSTableView – strange bouncing rows for Drag and Drop with NSTableViewDraggingDestinationFeedbackStyleGap
body: <p>I have a view-based instance of <code>NSTableView</code> for which I’ve been changing the <code>draggingDestinationFeedbackStyle</code>, as most <code>NSTableView</code> Drag and Drop questions have been updated with reference to this method of drag animation introduced in macOS 10.9.</p>
  
  <p>All works ok until I use <code>NSTableViewDraggingDestinationFeedbackStyleGap</code> for row reordering which results in my table rapidly bouncing a group of rows below the drop row.</p>
  
  <p>A clue appears in my table view delegate <code>-validateDrop:</code> method which is fired numerous times and returns a <code>-proposedRow:</code> that alternates between the desired drop row and the (total number-1) of rows in the table.</p>
  
  <p>A slow row move inspecting the <code>-validateDrop &lt;NSDraggingInfo&gt;</code> seems to point to an area just above where <code>NSTableViewDropOperation</code> becomes case On, i. e. just as it switches to case above. It only occurs within <code>DropOperationAbove</code>.</p>
  
  <p>If I choose <code>NSTableViewDraggingDestinationFeedbackStyle</code> none, regular or source list everything including the <code>-proposedRow:</code> in <code>-validateDrop:</code> works correctly.</p>
  
  <p>I have a custom <code>NSObject</code> set as <code>delegate</code> and also <code>dataSource</code> to fire <code>-validateDrop:</code>, while each <code>NSTextField</code> is bound to the <code>NSTableCellView</code> for specific values, so there is no <code>- (id)tableView:(NSTableView *)tableView viewForTableColumn:(nullable NSTableColumn *)tableColumn row:(NSInteger)row</code> method.</p>
  
  <p>On closer inspection, as dragging begins with <code>NSTableViewDraggingDestinationFeedbackStyleGap</code>the last row in my table is also removed and only reappears after the row has been dropped.  I have not included <code>-acceptDrop:</code> as the bouncing occurs before this is fired.</p>
  
  <pre><code>- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id &lt;NSDraggingInfo&gt;)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)op {
  
      NSLog(@"Validate Drop Fired in TableViewDataSource&amp;Delegate, TableView = %@",tv);
      NSLog(@"Dragging Info = %@",info);
      NSLog(@"proposedDropOperation = %lu",(unsigned long)op);
  
      //Destination is self
      if ([info draggingSource] == tv) {
  
      NSLog(@"destination is self, and row is %li",(long)row);
  
      return NSDragOperationMove;
      }
  return NSDragOperationNone;
  }
  
  - (void)awakeFromNib {
      [super awakeFromNib];
  
      [myTableView registerForDraggedTypes:[NSArray arrayWithObjects:[self.arrayController entityName], nil]];
  
      [myTableView setDraggingDestinationFeedbackStyle:NSTableViewDraggingDestinationFeedbackStyleGap];
  }
  
  - (BOOL)tableView:(NSTableView *)tv writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard*)pasteboard {
  
      NSLog(@"PasteBoard in TableViewDataSource&amp;Delegate, with Indexes, %@",rowIndexes);
      NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rowIndexes];
  
  
      [pasteboard declareTypes:[NSArray arrayWithObject:[self.arrayController entityName]] owner:self];
      [pasteboard setData:data forType:[self.arrayController entityName]];
  
      return YES;
  }
  
  -(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
  {
      return [[arrayController arrangedObjects] count];
  }
  </code></pre>
  
  <p>A single drag produces an output, for example:</p>
  
  <pre><code>destination is self, and row is 22
  destination is self, and row is 5
  destination is self, and row is 22
  destination is self, and row is 5
  destination is self, and row is 22
  destination is self, and row is 5
  </code></pre>
  
  <p>Causing a rapid bouncing in the NSTableView instance as it jumps between trying to drop at 5, then 22, then back to 5, and so on.</p>
  
  <p>I wonder if anyone has any ideas?</p>