我只是在学习 Objective C 和 Cocoa 的一些基本编程。我正在尝试从 NSTableView 获取一些数据。根据我在一个教程中阅读的内容,我写了这个:
NSArray * items = [[itemsTableView selectedRowEnumerator] allObjects];
但后来我了解到 selectedRowEnumerator
在 10.3 Panther 中已经被弃用,我应该使用 selectedRowIndexes
。
问题是,我没有找到如何实际使用返回的 NSIndexSet
来获得与上面编写的代码相同的结果。
所以,如果有人能给我提示,我将不胜感激。谢谢。
最佳答案
您可以像这样遍历 NSIndexSet
的索引:
- (void) goThroughIndexSet:(NSIndexSet *) anIndexSet
{
NSUInteger idx = [anIndexSet firstIndex];
while (idx != NSNotFound)
{
// do work with "idx"
NSLog (@"The current index is %u", idx);
// get the next index in the set
idx = [anIndexSet indexGreaterThanIndex:idx];
}
// all done
}
关于objective-c - 如何使用 NSTableView 的 selectedRowIndexes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2843294/