-(void)computeDistanceFrom:(CLLocation *)oldL tO:(CLLocation *)newL {
NSLog(@"oldL %@",oldL);
NSLog(@"newL %@",newL);
CLLocationDistance currentDistance = [oldL distanceFromLocation:newL];
NSLog(@"you have travel=%f",currentDistance);
distance = distance + currentDistance;
distanceInKm = distance/1000;
carbonSaveKg = distanceInKm*0.069565217;
fuelSaveLit = distanceInKm*0.073913043;
//set string to show
distanceLabelValue = [[NSString stringWithFormat:@"%1.3f",distanceInKm]retain];
distanceLabel.text = distanceLabelValue;
NSLog(@"distanceFromView=%f",distanceInKm);
carbonDioxideLabelValue = [[NSString stringWithFormat:@"%1.3f",carbonSaveKg]retain];
carbonDioxideLabel.text = carbonDioxideLabelValue;
NSLog(@"CO2FromView=%f",carbonSaveKg);
fuelLabelValue = [[NSString stringWithFormat:@"%1.2f",fuelSaveLit]retain];
fuelLabel.text = fuelLabelValue;
NSLog(@"FuelFromView=%f",fuelSaveLit);
}
我的应用会跟踪用户的当前位置。然后它按标签显示距离和几个值。当我离开包含此函数的视图时,我想将变量distanceInKm
,carbonSaveKG
和fuelLit
的值设置为0。
我的问题是当我再次回到这个视图时,变量的值仍然是之前存在的。 请帮我。
提前感谢您的帮助。
答案 0 :(得分:0)
插入此方法并在返回此视图之前调用它。
- (void)clearLabels {
distanceLabel.text = @"";
carbonDioxideLabel.text = @"";
fuelLabel.text = @"";
}