How to combine the changes of the CVO?

I have a pretty simple iPhone app that loads a UITableView result set into its model class and view controller, which is configured to watch these changes using QUO .

This system works well (much better than scattering the update code everywhere), except that when I get the results, I add them to the NSMutableArray support one by one. This causes a lot of KVO notifications, stunning my line animations in such a way that it looks weird. Is there a way to combine some KVO notifications so that changes can happen immediately and thus provide one KVO notification with one set of indices?

Alternatively, if I try calling -addObjectsFromArray to add my new results in batch mode, the necessary KVO notifications are never sent, so this should not be one of the observed methods, right? Would it be better to take care of this functionality by wrapping my changes with calls to will / didChangeValueForKey and creating an appropriate set of indexes?

+4
source share
2 answers

I have exactly the same problem. I don’t have the right solution, but you can find the answers to this page KVO Programming Guide :

You can implement these methods to simultaneously add individual objects to an array:

 -insert<Key>:atIndexes: and -remove<Key>AtIndexes (corresponding to the NSMutableArrayinsertObjects:atIndexes: and removeObjectsAtIndexes: methods) 

Hope this helps, Vincent.

+3
source

As for your second question, about using -addObjectsFromArray : this method does not really cause KVO notifications (for me, this method was removeAllObjects ). Alternatively, or alternatively, to implement array accessories , you can do the following:

 [[self mutableArrayValueForKey:@"key"] removeAllObjects]; 
+1
source

All Articles