for (int i = [timeArray count] - 1; i >= 0; i–) {
int timeComponent = [[timeArray objectAtIndex:i] intValue];
switch (i) {
case 3:
hours = timeComponent;
break;
case 2:
minutes = timeComponent;
break;
case 1:
seconds = timeComponent;
break;
case 0:
hundredths = timeComponent;
hundredths++;
break;
default:
break;
}
}
if (hundredths == 100) {
seconds++;
hundredths = 0;
}
else if (seconds == 60) {
minutes++;
seconds = 0;
minutes = 0;
}
self.hr.text = [NSString stringWithFormat:@"%.0d", hours];
self.min.text = [NSString stringWithFormat:@"%.2d", minutes];
}
当我执行此代码时,在for循环中获取异常错误。我可以克服这个问题。请建议我。提前谢谢你
答案 0 :(得分:0)
将for循环更改为
for (int i = [timeArray count] - 1; i >= 0; i-–) {
int timeComponent = [[timeArray objectAtIndex:i] intValue];
答案 1 :(得分:0)
你没有递减 i (i-)的值。你想使用递减运算符,但(i-)这不是递减运算符。所以请关注我
for (int i = [timeArray count] - 1; i >= 0; i–-) // ----- here your problem use i-- instead of i-
{
}