0

如何检查 NSIndexPath 对象的集合是否在特定部分中有项目?我不关心该行,并且想知道它是否有特定部分的项目。

照原样,我已经根据程序中的行数静态地写出,因此,例如,具有 3 行的第 0 节看起来像:

if ([array containsObject:[NSIndexPath indexPathForItem:0 inSection:0]] || [array containsObject:[NSIndexPath indexPathForItem:1 inSection:0]] || [array containsObject:[NSIndexPath indexPathForItem:2 inSection:0]])
4

1 回答 1

1

假设array包含一个对象数组NSIndexPath

NSInteger someSection = ... // the section to check for
BOOL exists = NO;
for (NSIndexPath *path in array) {
    if (path.section == someSection) {
        exists = YES;
        break;
    }
}

if (exists) {
    // Yes, at least one of the index paths was for the desired section
}
于 2013-08-26T22:17:24.243 回答