cocoa - 如何使用 NSIndexSet

标签 cocoa foundation nsindexset

在 Objective-C 中,我的程序打开一个窗口并显示一个表格。我想要突出显示表格的指定行。

我该怎么做?

我似乎需要代码

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

我查看了开发人员文档,发现 BOOL 应该是 NO。

通过查看 NSIndexSet 文档,我无法弄清楚正确的语法应该是什么。

最佳答案

这将是正确的方法:

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

或者您可以使用 NSMutableIndexSet 作为随机索引:

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

等等

关于cocoa - 如何使用 NSIndexSet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4485769/

相关文章:

ios - 如何从 Progress 对象中删除一个 child ?

objective-c - 使用 componentsSeparatedByString 拆分 NSString

Objective-C:如何将 NSIndexSet 转换为 NSIndexPath

swift - 如何在 Swift 中从 IndexSetB 中删除 IndexSetA?

ios - 将 XCode 输出写入文件

cocoa - 如何在 Cocoa 中创建仅导入文档类型?

iphone - 什么时候在 Mac/iPhone 上使用 CALayer?

objective-c - 椭圆形 NSTextField?

swift - 为什么String.subscript(_ :) require the types `String.Index` and `Int` to be equal when there is no `Int` involved?

objective-c - 当用户在 NSAlert 后按 Enter 时未设置 NSIndexSet