![](/img/trans.png)
[英]Why doesn't Xcode 3.2.3 stop debugging my application when I hit home in the Simulator?
[英]In my pedometer application, why doesn't my NSTimer stop when I want it to?
朋友們,請幫助我。 我已經完成了一個步驟計數器。 我現在的問題是我的計時器從加速度計開始,但是在加速度計停止時並沒有停止。(計步器是一個用戶可以計算自己步數的應用程序。有了此信息,用戶就可以計算自己消耗的總卡路里,以及經過的總時間。)問題是我的計時器無法正常工作。 請幫幫我。
這是代碼
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];
}
}
我修復了代碼縮進以使其結構匹配的問題。 現在對您來說應該很明顯,如果您在加速度低於閾值時嘗試使計時器無效,則else
位置錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.