如何获取索引从NSIndexset到可可的NSArray? [英] How to get indexes from NSIndexset into an NSArray in cocoa?

查看:242
本文介绍了如何获取索引从NSIndexset到可可的NSArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从表视图中选择项目:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆