如何将类型转换为字符串iPhone?
发布时间:2020-12-14 19:48:39 所属栏目:百科 来源:网络整理
导读:我正在计算一个iPhone的速度,我需要知道如何将类型为double的变量calculateSpeed转换为类型字符串以显示在标签上. 这是我在标题中的内容: @interface myProject : UIViewController CLLocationManagerDelegate {double calculatedSpeed; UILabel *velocityL
我正在计算一个iPhone的速度,我需要知道如何将类型为double的变量calculateSpeed转换为类型字符串以显示在标签上.
这是我在标题中的内容: @interface myProject : UIViewController <CLLocationManagerDelegate> { double calculatedSpeed; UILabel *velocityLabel; } 这里是我主要的: -(void)speedLocation:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { double gpsSpeed = newLocation.speed; if(oldLocation != nil) { CLLocationDistance distanceChange = [newLocation getDistanceFrom:oldLocation]; NSTimeInterval sinceLastUpdate = [newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp]; calculatedSpeed = distanceChange / sinceLastUpdate; velocityLabel.text = calculatedSpeed; } } 注意我如何设置velocityLabel到calculateSpeed,它是一个类型为double的变量.所以它自然会给我错误:“setText:”的参数1不兼容的类型. 你的帮助非常感谢 谢谢! 解决方法velocityLabel.text = [NSString stringWithFormat:@"%g",calculatedSpeed]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |