I am starting to use the monitoring of key values, and the mutable array that I am observing gives me NSIndexSets (Ordered mutable to-many) in the change dictionary. The problem is presenting the table, as far as I know, wants me to give it NSArrays full of indexes.
I was thinking of implementing a custom method to translate one to the other, but it seems slow, and I get the impression that there should be a better way to do this by updating the table view when the array changes.
This is the method from my UITableViewDataSource.
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
switch ([[change valueForKey:NSKeyValueChangeKindKey] unsignedIntValue]) {
case NSKeyValueChangeSetting:
NSLog(@"Setting Change");
break;
case NSKeyValueChangeInsertion:
NSLog(@"Insertion Change");
NSIndexSet * indexes = [change objectForKey:NSKeyValueChangeIndexesKey];
[self.tableView insertRowsAtIndexPaths:<#(NSArray *)#> withRowAnimation:<#(UITableViewRowAnimation)#>
break;
case NSKeyValueChangeRemoval:
NSLog(@"Removal Change");
break;
case NSKeyValueChangeReplacement:
NSLog(@"Replacement Change");
break;
default:
break;
}
}
source
share