如何获取索引从NSIndexset到可可的NSArray? [英] How to get indexes from NSIndexset into an NSArray in cocoa?
问题描述
我从表视图中选择项目:
I'm getting the select items from a table view with:
NSIndexSet *selectedItems = [aTableView selectedRowIndexes];
在NSArray对象中获取索引的最佳方法是什么?
what's the best way to get the indexes in a NSArray object?
推荐答案
枚举集合,使NSNumbers脱离索引,将NSNumbers添加到数组。
Enumerate the set, make NSNumbers out of the indexes, add the NSNumbers to an array.
这是你的做法。我不确定我是否看到将一组索引转换为更低效的表示。
That's how you'd do it. I'm not sure I see the point in transforming a set of indexes into a less efficient representation, though.
要枚举一个集合,你有两个选项。如果您定位的是OS X 10.6或iOS 4,则可以使用 enumerateIndexesUsingBlock:
。如果您定位的是早期版本,则必须获取 firstIndex
,然后继续请求 indexGreaterThanIndex:
先前的结果,直到你得到 NSNotFound
。
To enumerate a set, you have two options. If you're targeting OS X 10.6 or iOS 4, you can use enumerateIndexesUsingBlock:
. If you're targeting earlier versions, you'll have to get the firstIndex
and then keep asking for indexGreaterThanIndex:
on the previous result until you get NSNotFound
.
这篇关于如何获取索引从NSIndexset到可可的NSArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!