我想将对象添加到 NSMutableArray 类型的实例 var 中,我在一个块中创建(reverseGeocodeLocation)。我可以看到已定义对象中的值。但我无法让它工作,将它们添加到实例变量中。
我已经考虑过 __block 或 __strong 前缀。但我似乎错过了什么。你能给我一个线索吗?运行块中的代码后,实例 var "tableviewRows" 仍然为空。
谢谢!塞巴斯蒂安
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *currentLocation = [locations lastObject];
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {
CLPlacemark *placemark = [placemarks lastObject];
CLLocation *userLocation = [placemark location];
NSString *latitude = [NSString stringWithFormat:@"Lat. %f degrees", userLocation.coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"Long. %f degrees", userLocation.coordinate.longitude];
NSString *altitude = [NSString stringWithFormat:@"Alt. %f m", userLocation.altitude];
NSString *speed = [NSString stringWithFormat:@"Speed %f m/s", userLocation.speed];
NSString *course = [NSString stringWithFormat:@"Course %f degrees", userLocation.course];
[self.tableViewRows insertObject:latitude atIndex:0];
[self.tableViewRows insertObject:longitude atIndex:1];
[self.tableViewRows insertObject:altitude atIndex:2];
[self.tableViewRows insertObject:speed atIndex:3];
[self.tableViewRows insertObject:course atIndex:4];
} else {
NSLog(@"%@", error.debugDescription);
}
}];
[self.tableView reloadData];
}