这个可以通过设置range来解决.
NSRange range = NSMakeRange(0, activeItems.count);
for (NSString *substr in activeItems)
{
if ([substr isEqualToString:@"1"])
{
NSInteger index = [activeItems indexOfObject:substr inRange:range];
NSLog(@"the object indix is: %d", index);
range.location = ++index;
range.length = activeItems.count - index;
}
}
当然,这种对collection的过滤操作,我建议用NSPredicate.不过你这个过滤也不算复杂,怎样都行.
不过我还是给你写出来方法.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES '1'"];
NSArray *resAry = [activeItems filteredArrayUsingPredicate:predicate];
NSRange range = NSMakeRange(0, activeItems.count);
for (NSString *substr in resAry)
{
NSInteger index = [activeItems indexOfObject:substr inRange:range];
NSLog(@"the object indix is: %d", index);
range.location = ++index;
range.length = activeItems.count - index;
}