如何将类型转换为字符串iPhone?

如何将类型转换为字符串iPhone?,第1张

概述我正在计算一个iPhone的速度,我需要知道如何将类型为double的变量calculateSpeed转换为类型字符串以显示在标签上. 这是我在标题中的内容: @interface myProject : UIViewController <CLLocationManagerDelegate> {double calculatedSpeed; UILabel *velocityLab 我正在计算一个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];
总结

以上是内存溢出为你收集整理的如何将类型转换为字符串iPhone?全部内容,希望文章能够帮你解决如何将类型转换为字符串iPhone?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1057636.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存