Objective c NSIndexPath中是否存在节

Objective c NSIndexPath中是否存在节,objective-c,nsindexpath,Objective C,Nsindexpath,如何检查NSIndexPath对象集合在特定节中是否有项?我不关心行,我想知道它是否有特定部分的项 按原样,我已经根据程序中的行数静态写出了,因此,例如,一个包含3行的节0如下所示: if ([array containsObject:[NSIndexPath indexPathForItem:0 inSection:0]] || [array containsObject:[NSIndexPath indexPathForItem:1 inSection:0]] || [array conta

如何检查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]])
if([array containsObject:[nsindepath indexPathForItem:0:0]].[array containsObject:[nsindepath indexPathForItem:1:0].[array containsObject:[nsindepath indexPathForItem:2:0]])假设
array
包含
nsindepath
对象的数组:

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
}

你肯定想要
&&
而不是
|
!?如果节中存在任何行,我只希望bool返回yes,换句话说,如果用户选择了一个特定的节,那么您将使用一个从
0
N
的循环,如果您捕获到
[array containsObject:[nsindepath indexPathForItem:I instation:0]
返回
YES
。谢谢!min charsI的额外单词与此方法一起使用case语句。尽管此消息没有类方法,但效果相当好。