2014-02-19 5 views
0

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"으로 변경되었음을 확인했습니다.

+0

'[placesMapView removeAnnotations : placesMapPointsArray];를'[placesMapView removeAnnotations : placesMap.annotations]; '로 변경해보십시오. – JoeFryer

+0

@JoeFryer가 작동하지 않았습니다. 지도보기에 특수 효과를 추가하지 않았습니다. – mcphersonjr

+0

두 번째로'if' 문이 트리거되지 않습니다? –

답변

1

사용자 의견에 따르면 placesChamberArray에는 두 번째 실행시 'COC'범주의 개체가 없다는 것이 분명합니다. 그것이 있었다면 placesMapPointsArray는 몇 가지 항목을 가져야하지만 NSLOg 문은 그렇지 않다고 말합니다. isEqualToString 뒤에 NSLog를두고 실행 중이라는 것을 보여줌으로써 이것을 확인할 수 있습니다.

+0

Craig, 대답 주셔서 감사합니다.하지만 placesChamberArray는 for 루프가있는 placesPointPointArray를 만듭니다. 해당 placesMapPointsArray 올바른 번호의 개체, 올바른 데이터 및 정확한 tealAnnoationClass 적용하는 볼 수 있습니다. 그러나 그것은 결코지도에 도착하지 않습니다. – mcphersonjr

+1

귀하의 의견을 잘못 읽었습니다. placesMapPointsArray에 항목이 있지만 addAnnotations를 호출 한 다음 annotations.count가 0을 반환한다고 말하면 내게 불가능한 것 같습니다. 여기에 더 많은 코드가 있어야합니다. – Craig

+0

내 필터에 사용하고있는 [ECSlidingViewController] (https://github.com/ECSlidingViewController/ECSlidingViewController)가 밝혀졌습니다. 일단 이것을 제거하면 효과가있었습니다. 내지도보기를 취소하고 새로운 주석을 삽입하지 못하게하는 것 같습니다. – mcphersonjr

0

새 개체를 배열에 추가 한 후에 [placesMapView addAnnotations:placesMapPointsArray]에 다시 전화 했습니까?

+0

대답 질문에 대한 답변으로 ** Craig의 ** 질문과 관련하여 직접 의견을 참조하십시오. – mcphersonjr