如何检查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]])
答案 0 :(得分: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
}