0
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 循环中出现异常错误。我该如何克服这个问题。请建议我。先感谢您

4

2 回答 2

0

将您的 for 循环更改为

for (int i = [timeArray count] - 1; i >= 0; i-–) {
        int timeComponent = [[timeArray objectAtIndex:i] intValue];
于 2013-07-30T07:07:19.470 回答
0

您没有减少i (i-) 的值。而且您想使用减量运算符,但是(i-)这不是减量运算符。所以请关注我

for (int i = [timeArray count] - 1; i >= 0; i–-) // ----- here your problem use i-- instead of i- 
{
}
于 2013-07-30T07:13:07.717 回答