objective-c - 查找 nsindexset 中的第 n 个条目

标签 objective-c ios xcode nsarray nsindexset

<分区>

假设我有一个名为 aSetNSIndexSet,其编号范围为 26-89。

[aSet firstIndex] 给我 26

[aSet lastIndex] 给我 89

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

最佳答案

我不认为 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

关于objective-c - 查找 nsindexset 中的第 n 个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13244001/

上一篇:objective-c - RestKit 对象映射失败取决于属性名称

下一篇:ios - 设置应用程序中使用的提示警报

相关文章:

ios - 将传入消息附加到 ChatViewController collectionview (XMPPFramework+JSQMessagesViewController)

iphone - 如何在我们的 iPad 或 iPhone 应用程序中打开应用程序商店?

ios - Xcode 10 : Ambiguous Constraints Error When Adding Simple Constraints

objective-c - 如何在 Objective C 中安排方法调用

ios - 如何在 iOS 中以 url 的形式发布数据?

CGBitmapInfo 上的 Objective-C 到 Swift 转换问题

iphone - UISearchBar 中范围按钮文本的颜色

objective-c - 是否有用于 gSOAP 的 Objective-C 包装器?

ios - requestAVAssetForVideo 在获取一些视频时似乎挂起

ios - 快速加载更多数据会重复已经存在的单元格