NSIndexSet countOfIndexesInRange
- (NSUInteger)countOfIndexesInRange:(NSRange)indexRange
Parameters
indexRange
Index range being inquired about.
Return Value of [NSIndexSet countOfIndexesInRange]
Number of indexes in the index set that are members of indexRange.
NSIndexSet countOfIndexesInRange example.
NSArray *objectsToMove = [your_array objectsAtIndexes: rowIndexes];
// If any of the removed objects come before the row
// we want to decrement the row appropriately
row -= [rowIndexes countOfIndexesInRange: (NSRange){0, row}];
[your_array removeObjectsAtIndexes:rowIndexes];
[your_array replaceObjectsInRange: (NSRange){row, 0}
withObjectsFromArray: objectsToMove];
// If any of the removed objects come before the row
// we want to decrement the row appropriately
row -= [rowIndexes countOfIndexesInRange: (NSRange){0, row}];
[your_array removeObjectsAtIndexes:rowIndexes];
[your_array replaceObjectsInRange: (NSRange){row, 0}
withObjectsFromArray: objectsToMove];
Example of [NSIndexSet countOfIndexesInRange].
- (void) moveSelectedObjectsToRow:(NSUInteger)row {
> NSIndexSet *indexes = [(NSArrayController*)self.representedObject
> selectionIndexes];
> NSRange rangeAbove = NSMakeRange(0, row); // Range of all objects above
> row in table.
> NSUInteger numAbove = [indexes countOfIndexesInRange:rangeAbove]; // Num
> selected above row in table.
> NSUInteger newRow = row - numAbove; // Where we move selection to.
> [self.parentBase moveSublistObjectsAtIndexes:indexes toIndex:newRow]; //
> Replace this for Arrays.
> }
> NSIndexSet *indexes = [(NSArrayController*)self.representedObject
> selectionIndexes];
> NSRange rangeAbove = NSMakeRange(0, row); // Range of all objects above
> row in table.
> NSUInteger numAbove = [indexes countOfIndexesInRange:rangeAbove]; // Num
> selected above row in table.
> NSUInteger newRow = row - numAbove; // Where we move selection to.
> [self.parentBase moveSublistObjectsAtIndexes:indexes toIndex:newRow]; //
> Replace this for Arrays.
> }