2012-11-07 1 views
4

다음 이미지와 같이 주석 제목을 표시하는 데 문제가 있습니다. 첫 번째 이미지는 가치를 아주 잘 나타냅니다. 반면에 값이 세 자리수가되면 제목은 두 번째 이미지에 표시된 것처럼 세 개의 점을 표시합니다. 이 문제를 해결하는 방법을 알고 싶습니다. 어떤 생각이라도 환영 할 만하다. 미리 감사드립니다, 감사합니다! 나는 참조 용으로 여기에 내 코드를 넣었다.지도 주석 showCallout-iOS

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation { 
    MKAnnotationView *pinView=nil; 
    if(![annotation isKindOfClass:[Annotation class]]) // Don't mess user location 
     return nil; 

    static NSString *defaultPinID = @"StandardIdentifier"; 
    pinView = (MKAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
    if (pinView == nil){ 
     pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID]; 
    } 

    if ([annotation isKindOfClass:[Annotation class]]) { 
     Annotation *a = (Annotation *)annotation; 

     pinView.image = [ZSPinAnnotation pinAnnotationWithColor:a.color]; 
     pinView.annotation = a; 
     pinView.enabled = YES; 
     pinView.centerOffset=CGPointMake(6.5,-16); 
     pinView.calloutOffset = CGPointMake(-11,0); 

    } 

    pinView.canShowCallout = YES; 
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [rightButton setTitle:annotation.title forState:UIControlStateNormal]; 
    [pinView setRightCalloutAccessoryView:rightButton]; 
    pinView.leftCalloutAccessoryView = [[UIView alloc] init]; 
    pinView.leftCalloutAccessoryView=nil; 

    return pinView; 
    } 

내 showCallout 제목은 다음 코드 업데이트됩니다 :

NSNumber *attr2=[attr valueForKey:@"ozone_level"]; 
annotation.title=[NSString stringWithFormat:@"Ozone Level:%@",[attr2 stringValue]]; 

enter image description here enter image description here

+0

어떤 iOS 버전이 있습니까? – detunized

+0

내 버전은 iOS 6.0 –

+0

안녕하세요 @ user1724168, 내 대답은 iOS 6에서 시뮬레이터와 기기 모두에서 작동합니다. :) –

답변

2

제목이 변경되면 설명 선보기의 레이아웃이 다시 계산되지 않습니다. 어쩌면 그 버그 보고서를 제출해야합니다.

강제로 다시 레이아웃을 적용하려면 설명 선이 표시되는 경우 프로그래밍 방식으로 주석을 선택 해제하고 선택할 수 있습니다. 그것은 애니메이션,하지만 콜 아웃의 폭 변경 아니에요 : 주석의 제목이 주석에 텍스트 레이블로 사용되는 어쨌든, 당신은이 라인을 삭제해야

NSNumber *attr2=[attr valueForKey:@"ozone_level"]; 
annotation.title=[NSString stringWithFormat:@"Ozone Level:%@",[attr2 stringValue]]; 


if ([self.mapView viewForAnnotation:annotation] != nil) { 
    NSArray *selectedAnnotations = self.mapView.selectedAnnotations; 
    if ((selectedAnnotations != nil) && ([self.mapView.selectedAnnotations indexOfObject:annotation] != NSNotFound)) { 
     [self.mapView deselectAnnotation:annotation animated:NO]; 
     [self.mapView selectAnnotation:annotation animated:NO]; 
    } 
} 

을 :

[rightButton setTitle:annotation.title forState:UIControlStateNormal]; 

업데이트 :

@detunized 솔루션은 애니메이션과 함께 제공됩니다. 불필요한 UIView를 만드는 대신 버튼보기를 제거하고 다시 추가하는 것이 더 좋습니다.

NSNumber *attr2=[attr valueForKey:@"ozone_level"]; 
annotation.title=[NSString stringWithFormat:@"Ozone Level:%@",[attr2 stringValue]]; 

MKAnnotationView *annotationView = [self.mapView viewForAnnotation:annotation]; 
// The annotation must be visible, otherwise a refresh isn't needed 
if (annotationView != nil) { 
    NSArray *selectedAnnotations = self.mapView.selectedAnnotations; 
    // The annotation must be selected, otherwise a refresh isn't needed 
    if ((selectedAnnotations != nil) && ([self.mapView.selectedAnnotations indexOfObject:annotation] != NSNotFound)) { 
      // Unset and re-set the right button to force relayout 
      UIView *view = annotationView.rightCalloutAccessoryView; 
      annotationView.rightCalloutAccessoryView = nil; 
      annotationView.rightCalloutAccessoryView = view; 
    } 
} 
+0

[annotationView setNeedsLayout]이 대신 작동합니까? – Brendon

+0

아니요, 불행히도 아닙니다. –

0

나는이 문제에 대한 올바른 해결책을 모르지만, 난에 대한 해키 하나가 당신. 뷰의 재 레이아웃을 트리거해야하며 액세서리 뷰를 망칠 수 있습니다. 여기서 왼쪽 액세서리보기를 사용하지 않으므로 이것을 무언가로 설정할 수 있으며 다시 nil으로 설정할 수 있습니다. 이처럼 :

self.pin.title = @"Ozone Level: 100"; 
self.pin_view.leftCalloutAccessoryView = [[[UIView alloc] init] autorelease]; 
self.pin_view.leftCalloutAccessoryView = nil; 

나는 시도하고 있지 UIView 모든 시간을 만들

자주 그때는 좋은 그렇게한다면 아이폰 OS 6에서 테스트가 아니라 뭔가를 다시 사용할 수 없습니다 아이폰 OS 5에서 작동합니다.

rightCalloutAccessoryView을 업데이트 할 때 동일한 문제가 발생했습니다. 내가 처음에 그것을 nil으로 설정하고 바로 그걸 내가 처음부터 필요로하는 것으로 설정하면 효과가있었습니다.

+0

위의 업데이트 된 코드를 참조하십시오. 아직도 아직 취급하지! –

+0

음, iOS 6에서 해킹이 작동하지 않을 수 있습니다. – detunized

+0

@ user1724168, 나중에 다른 곳에서 '제목'을 업데이트하고 있습니까? 게시 한 코드는 특수 효과를 만드는 장소를 보여줍니다. 문제는 나중에 텍스트를 업데이트 할 때 발생합니다. 내 해킹을 그 장소로 옮겨야합니다. 여기서 당신은 그것을 필요로하지 않습니다. – detunized