How to use NSIndexSet

hertopnerd picture hertopnerd · Dec 20, 2010 · Viewed 46k times · Source

In Objective-C, my program opens a window and displays a table. I want to have a specified row of the table highlighted.

How do I do this?

I seem to need the code

[myTableView selectRowIndexes:(NSIndexSet *) byExtendingSelection:(BOOL)];

I looked at the developer documentation, and figured out that the BOOL should be NO.

By looking at the NSIndexSet docs, I can't figure out what the right syntax should be.

Answer

holex picture holex · Apr 26, 2012

it would be the proper way:

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

or you can use the NSMutableIndexSet for the random indexes:

NSMutableIndexSet *mutableIndexSet = [[NSMutableIndexSet alloc] init];
[mutableIndexSet addIndex:0];
[mutableIndexSet addIndex:2];
[mutableIndexSet addIndex:9];

etc.