MKMapView에 사용자 정의 주석을 성공적으로 추가하고 성공적으로 주석을 제거합니다. 하위보기 컨트롤러를 사용하여 내지도보기에서 특수 효과를 필터링하고 있습니다. 모든 주석을 제거 할 때지도 뷰에 새 주석을 추가하는 데 문제가 있습니다. 올바른 데이터가 내 어노테이션 배열에 추가되지만 내 배열을 사용하여 어노테이션을 추가하면 어노테이션이 맵보기로 표시되지 않습니다. 감사합니다. 감사합니다.iOS에서 모든 맞춤 주석을 제거하고 새로운 맞춤 주석을 추가하는 적절한 방법은 무엇입니까?
커스텀 어노테이션에 breakpoint를 놓을 때 if 문은 처음으로 어노테이션을 맵 뷰에 추가 할 때 호출되지만 두 번째는 그렇지 않을 것입니다.
내가 주석 추가 곳입니다 :
for (placesChamber *placesObject in placesChamberArray) {
if ([placesObject.category isEqualToString:@"COC"]) {
tealAnnotation *annotationTeal = [[tealAnnotation alloc] init];
CLLocationCoordinate2D coordinates = CLLocationCoordinate2DMake([placesObject.latitude doubleValue],[placesObject.longitude doubleValue]);
annotationTeal.coordinate = coordinates;
annotationTeal.title = placesObject.name;
annotationTeal.tealAnnotationClass = placesObject;
[placesMapPointsArray addObject:annotationTeal];
}
}
[placesMapView addAnnotations:placesMapPointsArray];
NSLog(@"Number of Places found: %lu",(unsigned long)placesMapPointsArray.count);
NSLog(@"Number of Places on map: %lu",(unsigned long)placesMapView.annotations.count);
if (!placesMapView.annotations || !placesMapView.annotations.count) {
NSLog(@"There are 0 annotations.");
}//end if
이 사용 내 사용자 지정 주석입니다 : (MKAnnotationView *)지도보기 (MKMapView *)를 맵보기 (Map View) viewForAnnotation (ID) 주석
if ([annotation isKindOfClass:[tealAnnotation class]]) // for
{
// try to dequeue an existing pin view first
static NSString *TealAnnotationIdentifier = @"tealPin";
MKPinAnnotationView *tealPinView =
(MKPinAnnotationView *) [self.placesMapView dequeueReusableAnnotationViewWithIdentifier:TealAnnotationIdentifier];
if (tealPinView == nil)
{
// if an existing pin view was not available, create one
MKPinAnnotationView *tealAnnotationView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:TealAnnotationIdentifier];
tealAnnotationView.image = [UIImage imageNamed:@"teal_pin.png"];
tealAnnotationView.canShowCallout = YES;
tealAnnotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
CGSize newSize;
newSize.width = 32;
newSize.height = 32;
UIGraphicsBeginImageContext(newSize);
[tealAnnotationView.image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
tealAnnotationView.image = newImage;
return tealAnnotationView;
}
else
{
tealPinView.annotation = annotation;
}
return tealPinView;
}
다음은 주석을 제거하는 방법입니다.
[placesMapView removeAnnotations:placesMapPointsArray];
[placesMapPointsArray removeObjectsInArray:placesMapPointsArray];
정보를 얻은 후 fr om comments 내 mapView에 대한 viewDelegate가 "nil"으로 변경되었음을 확인했습니다.
'[placesMapView removeAnnotations : placesMapPointsArray];를'[placesMapView removeAnnotations : placesMap.annotations]; '로 변경해보십시오. – JoeFryer
@JoeFryer가 작동하지 않았습니다. 지도보기에 특수 효과를 추가하지 않았습니다. – mcphersonjr
두 번째로'if' 문이 트리거되지 않습니다? –