0

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 TableViewControllerfor 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?

Tim
  • 175
  • 1
  • 1
  • 12

1 Answers1

1

It is bad practice to place mapview in uitableviewcell unless you really need that. Best way to do is create static image for the location and use it using uiimageview instead of mapview. Here is the API to create static image from map -> Click Here

Rokon
  • 355
  • 3
  • 11