如果不知道为什么会发生这种情况,我不能再过一天。我一直在使用Corelocation这里的iPhone应用程序的问题:IPhone浮点到字符串问题
GPSLocation.m - 发送长/纬度坐标这是彩车类 UserSettings.m(这是一个单 类)
_
UserSettings.m - 再投值到预定义的字符串从 float
例如strLongitude = [NSString stringWithFormat:@“%f”,paramLong];我可以跟踪出字符串就好了NSLog(@“Longitude string is%@”,strLongitude);
约strLongitude
- 一些注意事项是在头文件
- 属性被定义为(非原子, 保留)
- 合成
现在的问题: 当我在另一个类中需要这个变量时,我可以使用获取它的两种方法之一。无论是通过getter [UserSettings getLongitude]或访问属性[UserSettings strLongitude]
然后,当我跟踪出这个字符串时,我有时会得到一个badaccess错误或随机垃圾。如果我将字符串追踪为浮点数%F,则工作得很好。
这是怎么发生的?该字符串默认返回到变量的原始数据类型。
任何帮助,将不胜感激。
啊! @属性(非原子,保留)NSString * strLongitude; – 2009-12-21 23:14:58
但您需要使用self: self.strLongitude = [NSString stringWithFormat:@“%f”,paramLong]; 来调用setter(它保留)。只是踢,试试: strLongitude = ...; [strLongitude retain];看看有没有什么区别。 – Jeff 2009-12-22 03:04:28
宾果!我没有调用setter。 self.strLongitude工作得很好。谢啦! – 2009-12-22 22:36:28