gpt4 book ai didi

iOS 9 : MapView with multiple Annotations inside a UITableViewCell

转载 作者:行者123 更新时间:2023-11-29 00:43:22 26 4
gpt4 key购买 nike

上下文:我正在处理一个包含许多不同单元格的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com