Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa NSIndexSet : Multiple Indexes. How to create the index set, multiple indexes?

I am trying to figure out how to create a set of indexes of lets say (1, 2, 3) then use it in

- (void)selectRowIndexes:(NSIndexSet *)indexes byExtendingSelection:(BOOL)extend 

It's the (NSIndexSet *)indexes I do not know how to use / create / populate with indexes 1, 2, 3. Should I use a class method or instance method?

I tried a whole bunch of ways but I have no idea what I'm doing ...

like image 792
noyfbja Avatar asked May 10 '11 19:05

noyfbja


1 Answers

If the indexes are consecutive like in your example, you can use this:

NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, 3)]; 

If not, create a mutable index set and add the indexes (or ranges) one by one:

NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet]; [indexSet addIndex:3]; [indexSet addIndex:5]; [indexSet addIndex:8]; 
like image 167
Ole Begemann Avatar answered Sep 21 '22 06:09

Ole Begemann