iphone - iOS查询多维数组并返回索引路径

标签 iphone ios nsmutablearray

我有一个 NSMutableArray,它包含其他 NSMutableArray(我将它们称为子数组)。这些子数组每个都包含一个名为 id 的唯一变量。我想返回包含某个 id 的子数组的索引路径。例如,如果其中一个子数组的 id 为 25,我如何找到该子数组的索引路径(而不是子数组中 id 的索引路径)?

提前谢谢您。如果您有任何疑问,请告诉我。

干杯,埃文。

最佳答案

您基本上必须手动搜索所有子数组。例如:

NSUInteger outerIndex = [outerArray indexOfObjectPassingTest:^(id subarray, NSUInteger outerIdx, BOOL *stopOuter) {
    NSUInteger innerIndex = [subarray indexOfObjectPassingTest:^(id obj, NSUInteger innerIdx, BOOL *stopInner) {
        return [obj isEqual:searchTerm];
    }];
    return innerIndex != NSNotFound;
}];
NSUInteger indexes[] = {outerIndex, innerIndex};
NSIndexPath *indexPath = [NSIndexPath indexPathWithIndexes:indexes length:2];

关于iphone - iOS查询多维数组并返回索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5869817/

相关文章:

ios - UIModalPresentationStyle.CurrentContext Swift iOS 7

ios - 在 IOS 中从本地存储存储和检索 JSON 数据

ios - APNS 从多个服务器发送通知

ios - 如何在 iOS 上删除相册?

android - jQuery Mobile 在 ListView 中具有多个列

ios - 在 swift 3 中传递地址时在 map 中获取 "Cannot provide direction"?

objective-c - NSArray enmuerateUsingBlock,一个在另一个里面,如何停止外部枚举?

objective-c - 使用 valueForKey 将字符串数组转换为 nsnumbers 数组

iphone - 将核心数据添加到 XCode 4 中的现有项目

iphone - 如何创建新的CMAttitude引用系以使重力位于Y轴上