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?

4

1 回答 1

1

除非你真的需要,否则将 mapview 放在 uitableviewcell 中是不好的做法。最好的方法是为该位置创建静态图像,并使用 uiimageview 而不是 mapview 来使用它。这是从地图创建静态图像的 API ->单击此处

于 2016-08-14T08:06:37.747 回答