0

I implemented an NSArrayController subclass to implement row reordering with bindings, using the code included in this post as a starting point. In the -tableView:acceptDrop:row:dropOperation: method, I perform the following:

[self removeObjectAtArrangedObjectIndex:removeIndex];
[self insertObject:object atArrangedObjectIndex:insertIndex];

The above code updates the model twice (one for each statement). For my purposes, I would like to have only one update.

Is there any way to achieve this?

Thanks.

insys
  • 1,288
  • 13
  • 26
  • Why do you need the single update in the first place? That information might help us to get a better suited answer.. – cacau May 13 '14 at 06:01
  • As I mention in my question, I am implementing row reordering. I only consider that it is semantically appropriate to have a single update if a row gets rearranged (deleted+inserted) – insys May 14 '14 at 05:57

2 Answers2

0

There's always the possibility of replacing the entire array if you want to incorporate many changes to an array into a single operation.

This might have unexpected effects for e.g. objects in the UI bound to your array, though.

cacau
  • 3,606
  • 3
  • 21
  • 42
0

I ended up doing the following:

[_content removeObject: [objects objectAtIndex: removeIndex]]; // < Here's the hack
[self insertObject:object atArrangedObjectIndex:insertIndex];

Where _content is in fact the content array of the controller.
The above works fine in my case (as described in my question).

insys
  • 1,288
  • 13
  • 26