iOS 9 : MapView with multiple Annotations inside a UITableViewCell

标签 ios objective-c uitableview mapkit mapkitannotation

上下文: 我正在处理一个包含许多不同单元格的 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 时......它就像一个魅力......但是如果我回到上一个 View 并再次转至 TableViewController 它不起作用。 我已尝试对所有内容进行 NSLog,但输出是相同的,因此每次都会调用 mapPinForAddress

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

最佳答案

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

关于iOS 9 : MapView with multiple Annotations inside a UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38937974/

相关文章:

ios - 多次调用 estimatedHeightForRowAtIndexPath 导致不稳定的 uitableview

ios - 如何检查字符串是否包含空格/字母数字/等字符?

ios Instagram api POST 关系端点使用 Alamofire - 错误

ios - 创建一个自定义 View ,显示像 UITableViewCell 一样定义的 subview

ios - 画一个表盘状的线指向用户的触摸点

ios - Swift:根据其中的 UICollectionView 的大小扩展 UITableViewCell 高度

iphone - iPhone 导航栏按钮项 (UIButtonBarItem) 的错误

ios - 处理字典中的 null 和 NSDate

objective-c - glBindAttribLocation() 的某些名称不起作用。 Objective-C 问题?

iphone - 单元格 View 公开按钮及相关方法