下面的代码应该做到这一点:无论当前的运动员在哪里,当你点击下一个按钮时,下面的代码就会被执行。它应该将当前运动员更改为数组中的下一个运动员,然后当它到达最后一个人时,它需要循环回 0(第一个对象)。它确实做到了这一点。当我到达数组的末尾时,它会再次转到第一个人,这是正确的,但从那时起将跳过数组中的最后一个对象。知道为什么吗?
-(void)nextAthlete{
NSUInteger index = [_athleteArray indexOfObject:_currentAthlete];
Athlete *count = _athleteArray[index];
NSLog(@"Current Athlete:%@ Index: %lu",count,(unsigned long)index);
if(index < ((_athleteArray.count)-1)){
index++;
_currentAthlete = _athleteArray[index];
_evalSelected = [self getMostRecentEval];
[self updateInformation];
NSLog(@"Index after being smaller than the array count: %lu",(unsigned long)index);
}
if(index == ((_athleteArray.count)-1)){
_currentAthlete = _athleteArray[index];
_evalSelected = [self getMostRecentEval];
[self updateInformation];
index=0;
_currentAthlete = _athleteArray[index];
NSLog(@"Index after being equal to array count: %lu",(unsigned long)index);
}
if(index > ((_athleteArray.count)-1)){
index=0;
_currentAthlete = _athleteArray[index];
}
self.title = [NSString stringWithFormat:@"%@'s Evaluation",_evalSelected.whosEval.full];
}