【问题标题】:Finding the nth entry in an nsindexset [duplicate]在 nsindexset 中查找第 n 个条目 [重复]
【发布时间】:2012-11-06 03:37:38
【问题描述】:

假设我有一个名为aSetNSIndexSet,数字范围为26-89。

[aSet firstIndex] 给我 26

[aSet lastIndex] 给我 89

什么方法会给出第三个索引 (29)?

【问题讨论】:

标签: objective-c ios xcode nsarray nsindexset


【解决方案1】:

我不认为NSIndexSet 可以用于这样的访问。您需要遍历它。比如——

int indexIwantToFind = 2;
int valueAtThisIndex = [aSet firstIndex];
for(int i = 0; i < indexIwantToFind; i++){
    valueAtThisIndex = [aSet indexGreaterThanIndex:valueAtThisIndex];
}
NSLog(@"%d", valueAtThisIndex); //This will give you 39

【讨论】:

  • 如果索引集包含数字 26、30、39、69,那么这个方法会给出第二个索引 (30) 而不是它应该是 (39) 的值
猜你喜欢
  • 2012-01-07
  • 2014-02-04
  • 2011-05-30
  • 2012-09-16
  • 1970-01-01
  • 2021-10-21
  • 2011-08-29
  • 2020-03-08
  • 2015-11-01
相关资源
最近更新 更多