2013-07-30 104 views
0
当我excuting这个代码获得异常错误在for循环我。怎么能够克服这个problem.please建议我
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]; 
    } 

。 三江源提前越来越excepected表达错误

+1

使用i--而不是i- – CRDave

回答

0

更改您的for循环

for (int i = [timeArray count] - 1; i >= 0; i-–) { 
     int timeComponent = [[timeArray objectAtIndex:i] intValue]; 
0

你不是递减的值i(异)。而你想使用递减运算符,但(i-)这不是递减运算符。所以请跟着我

for (int i = [timeArray count] - 1; i >= 0; i–-) // ----- here your problem use i-- instead of i- 
{ 
} 
+0

您的答案与以前的Ramshad答案有何不同。 – CRDave

+0

他没有解释原因。所以我解释了它。 –

+0

比你应该对这个答案发表评论。只有真正的答案不同时,新的答案才应发布。否则将评论或编辑原始答案。 – CRDave