2013-07-30 99 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