【发布时间】:2013-03-30 13:51:45
【问题描述】:
我实际上是在设计一个简单的应用程序来利用核心位置来获取位置详细信息,同时显示纬度和经度。 但是当我运行它时,我收到如下错误消息:
由于未捕获的异常“NSUnknownKeyException”而终止应用程序, 原因:'[setValue:forUndefinedKey:]: 此类对于 Latitude 键的键值编码不兼容。'
我也合成了属性。我仍然不知道它抛出错误的确切原因!
rajViewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface rajViewController : UIViewController <CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet UILabel *latitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *longitudeLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
- (IBAction)getCurrentLocation:(id)sender;
@end
rajViewController.m
@interface rajViewController (){
CLLocationManager *locationManager;
CLGeocoder *geo;
CLPlacemark *placemark;
}
@end
@implementation rajViewController
//@synthesize placemark;
@synthesize latitudeLabel;
@synthesize longitudeLabel;
.
.
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newPlace = [[CLLocation alloc]init];
newPlace = [locations lastObject];
NSLog(@"the latitude is : %f",newPlace.coordinate.latitude);
if (newPlace!=nil){
self.latitudeLabel.text = [NSString stringWithFormat:@"%f", newPlace.coordinate.latitude];
self.longitudeLabel.text = [NSString stringWithFormat:@"%f",newPlace.coordinate.longitude];
}
}
任何帮助将不胜感激。
感谢和问候, 拉吉。
【问题讨论】:
-
嗨 Raj,问题可能出在初始化你的 NSDictionary 之前,你在字典中为 somekey 设置值首先检查它是否没有创建,只需创建它@Raj0689
-
嗨,苏甘!对不起..但是你能不能具体一点..因为我是objective-C的新手:(
-
嗨,你正在尝试为未创建的字典中的键设置值,如果它是 null(dict),则在将值设置为 dict 之前放置 NSLog。只需执行 dictname=[[NSMutableDictionary alloc]init ] k.如果你没有得到,请告诉我
-
或者直接在 NSLog 中打印你的回复
标签: xcode ios6 core-location cllocationmanager