【发布时间】:2011-07-21 19:19:42
【问题描述】:
我正在使用 CLLocationManager 尝试获取我的用户的纬度和经度,将它们转换为 NSString 并使用以下代码在 UILabel 的屏幕上显示它们;
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D location=newLocation.coordinate;
NSString *latLong = [NSString stringWithFormat:@"%f,%f",location.latitude,location.longitude];
locationView.text = latLong;
}
一切编译和运行都没有问题,但 UILabel 'locationView' 没有被填充。我已经测试了创建一个 NSString 并尝试了它的工作正常。
任何想法我的错误在哪里?
【问题讨论】:
-
你试过
NSLog-ing 纬度和经度,看看它们是否存在? -
locationView 是如何添加到视图层次结构中的?如果是插座,是否已连接?
-
您确定正在调用方法 (locationManager:didUpdateToLocation:...) 吗?基本上按照pixelfreak的建议测试一下。
-
@pixelfreak location 是一个结构,所以它存在,如果值“不”存在,它们可能是 0,所以它仍然看起来像 @"0.00000,0.000000"。
-
当我在 latLong 上运行 NSLog 时,它不会在日志中显示任何内容,所以显然它什么都没有
标签: iphone objective-c xcode nsstring uilabel