Row animations for NSTableView with Bindings

Viewed 542

I have an NSTableView which uses an array controller as binding to a dynamic array and it works great.

Now I realized that when I am appending / inserting an element to the array the row is directly added to the table view without the row insert animation. When I am often adding elements to the array the table view looks weird due to the missing animation.

Is there any "official" way or workaround to get the row animations when I am inserting or removing an element of the dynamic array?

1 Answers

I know this questions is pretty old, but I ran into a similar issue when trying to animate an insertion within a NSTableView which uses bindings. This is what I ended up doing:

  1. Unbind the array controller from the tableview content.
  2. Insert the new object into the array controller (without unbinding first this would automatically insert it into the tableview without animation).
  3. Animate the tableview insertion.
  4. Re-bind the array controller to the tableview content.
    // insertIndex and objectToInsert established earlier
    [self.myTableView unbind:NSContentBinding];
    [self.myArrayController insertObject:objectToInsert atArrangedObjectIndex:insertIndex];
    [NSAnimationContext runAnimationGroup:^(NSAnimationContext * _Nonnull context) {
        [self.myTableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:insertIndex] withAnimation:NSTableViewAnimationSlideDown];
    } completionHandler:^{
        [self.myTableView bind:NSContentBinding toObject:self.myArrayController withKeyPath:@"arrangedObjects" options:@{NSRaisesForNotApplicableKeysBindingOption : @(YES)}];
    }];
Related