【问题标题】:iOS 9: MapView with multiple Annotations inside a UITableViewCelliOS 9:在 UITableViewCell 内具有多个注释的 MapView
【发布时间】:2016-08-13 23:52:35
【问题描述】:

背景: 我正在开发一个包含许多不同单元格的 TableView:其中一个应该包含一个包含多个注释的 MapView。

到目前为止我得到了什么:

//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];
            }
}];

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;

}

这是我的问题:

当我第一次加载TableViewController...它就像一个魅力...但是如果我回到以前的视图并再次转到TableViewController,它就不起作用了。 我试过 NSLog 一切,但输出是一样的,所以mapPinForAddress 每次都会被调用。

有没有人有一些提示或一些代码?

【问题讨论】:

  • geocodeAddressString 如果调用次数过多,可能会失败。

标签: ios objective-c uitableview mapkit mapkitannotation


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-14
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    相关资源
    最近更新 更多