0
上下文: 我正在使用包含許多不同單元格的TableView:其中一個應該包含一個MapView,其中包含多個批註。iOS 9:在UITableViewCell中帶有多個批註的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 [email protected]"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
我t不起作用。 我試圖NSLog的一切,但輸出是相同的,所以mapPinForAddress
每次被調用。
有沒有人有一些提示或者一些代碼?
如果調用次數太多,geocodeAddressString會失敗。 – Brandon