Context: I am working on a TableView which contains many different cells: One of them should contain a MapView with multiple annotations in it.
What I have got so far:
//address comes in this format: NSString = @"myStreet myNumber, myZIP myCity, Germany";
- (void) mapPinForAddress: (NSString *)address {
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
[geoCoder geocodeAddressString:adresse completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placeMark = [[MKPlacemark alloc] initWithPlacemark:topResult];
MKPointAnnotation *adressPoint = [[MKPointAnnotation alloc] init];
adressPoint.coordinate = placeMark.coordinate;
adressPoint.title =@"Title";
adressPoint.subtitle = address;
[mapPins addObject:adressPoint];
}
}];
and inside of cellForRowAtIndexPath
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == mapViewSection) {
myMapCell *cell = [tableView dequeue...];
[cell.mapView addAnnotations:mapPins];
[cell.mapView showAnnotations:mapPins animated:YES];
return cell;
}
And here is my problem:
When I load the TableViewController
for the first time... It works like a charm... But if I go back to the previous View and segue again to the TableViewController
it doesn't work.
I have tried to NSLog everything but the outputs are the same, so mapPinForAddress
gets called everytime.
Does anyone have some hints or maybe some code?