2010-07-03 2 views
0

도와주세요. 친구. 계단 카운터 만들기가 끝났습니다. 내 문제는 이제 내 타이머가 가속도계로 시작하지만 가속도계가 멈 추면 멈추지 않는다는 것입니다. (보수계는 사용자가 자신의 단계를 계산할 수있는 응용 프로그램입니다.이 정보로 사용자는 총 칼로리를 계산할 수 있습니다 , 총 경과 시간) 문제는 제 타이머가 제대로 작동하지 않는다는 것입니다. 제발 도와주세요. 여기내 보수계 응용 프로그램에서 왜 내 NSTimer가 멈추지 않을까요?

내가 그 구조와 일치하는 코드의 들여 쓰기를 고정 코드

if ( fabsf(acceleration.y) > progressAsInt) { 
     steps++; 
     timer1 = [NSTimer scheduledTimerWithTimeInterval:(.01) target:self selector:@selector(timepassed) userInfo:nil repeats:YES]; 


     NSString *stepcount = [NSString stringWithFormat:@"%d", steps]; 
     [stepstaken setText:stepcount]; 

     //it's for the MPH speed calculation formula changes can be happen 
     /*formula mph= miles/hour 
     0.5miles 
     10minutes = 10/60 hours = 0.1667 
     mph=0.5/0.1667*/ 

     mspeed = (TotalDistance *3600)/60; 
     //mspeed =(steps*steplength)/63360*60; 
     NSString *speed = [NSString stringWithFormat:@"%2.2f",mspeed]; 
     [mSpeed setText:speed]; 


     //this for calculation of miles 
     TotalDistance = (steps *steplength)/1500; 
     NSString *distance =[NSString stringWithFormat:@"%5.3f",TotalDistance]; 
     [miles setText:distance]; 


     if (steps%20==0) 
     { 
      //And this for calorie calculation 
      cal++; 

      NSString *cal1 = [NSString stringWithFormat:@"%d",cal]; 
      [calorie setText:cal1]; 
     }else{ 
      [timer1 invalidate]; 

     }   
} 
+4

새로운 질문을하는 대신 이전 질문을 수정하는 것이 좋습니다. http://stackoverflow.com/questions/3171716/pedometer-app-in-iphone 또한 이전 질문에 대한 답변을 수락하십시오. – Eiko

+0

@ Harishdy007 : @Eiko가 맞습니다. 이전 질문을 편집해야합니다. 그것은 아무 대답도 없기 때문에, 나는 전방 갔다 다만 그것을 삭제했다. –

답변

0

입니다. 가속도가 임계 값 아래에있을 때 타이머를 무효화하려는 경우 else이 잘못된 위치에 있다는 것을 알고 있어야합니다.