目前正在使用Xcode 6;
使用Mapkit.h和coreLocation框架在iOS 8.1中生成地图视图时,单击按钮而不是在标签中显示纬度和经度值时,它显示崩溃错误:无法识别的选择器发送到实例0x797a4e20
GPSController.m中的
- (IBAction)tap:(id)sender {
NSLog(@"button clicked");
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[locationManager startMonitoringSignificantLocationChanges];
}
应该获取此值:
(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"location info object=%@", [locations lastObject]);
CLLocation* location = [locations lastObject];
NSLog(@"latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
self.lat.text = [NSString stringWithFormat:@"%+.6f", location.coordinate.latitude];
self.longi.text = [NSString stringWithFormat:@"%+.6f", location.coordinate.longitude];
[self performSegueWithIdentifier:@"Map" sender:self];
}
答案 0 :(得分:0)
您还应该给出
的定义(void)locationError:(NSError *)error in{
//你的逻辑 }
答案 1 :(得分:0)
在您的代码中执行以下评论。
action:@selector(tap:)
代替action:@selector(tap)
处理位置管理器的didFailWithError
代理以获取有关错误的更多详细信息
语法:
(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
检查 Segue with ID'Map'确实存在