2010-03-22 6 views
3

편집 됨 * 아직이 솔루션을 찾지 못했습니다. 아무도 도와 줄 수 있습니까? 내 문제는 이것과 유사하지만 게시 된 답변이 나를 위해 작동하지 않습니다. MKMapView refresh after pin moves * 끝 편집더 많은 결과를로드하는 동안 MKMapView - viewForAnnotation이 호출되지 않음

검색이 가능한지도보기가 있습니다. 사용자가 검색을 클릭하면 맞춤보기 특수 효과가지도보기에 추가됩니다. 검색은 '더 많은로드'링크가 포함 된 20 개의 결과를 반환합니다. 더 많은로드를 클릭하면지도보기에 더 많은 특수 효과를 추가해야합니다.

문제는 - 주석은지도보기에 추가되지만지도에는 표시되지 않습니다. 확대 또는 축소하여지도 영역을 변경하면 핀이 표시됩니다.

나는 'load more'를 눌렀을 때 viewForAnnotations :가 호출되지 않음을 알게되었습니다. 나는 이것을 발동시키는 방법을 모르겠다. 하나?

-(void)completedSearch:(NSNotification *)resultNotification 
{ 
    //begin loop 
    //get coordinate 
    customAnnotation *annot = [[customAnnotation alloc] initWithCoordinate:coordinate]; 
    //set title subtitle 
    [annotationsArray addObject:annot]; 
    //end loop 
    [mView addAnnotations:annotationsArray]; 
    [mView setRegion:region animated:YES]; 
    [mView regionThatFits:region]; 
} 

    //custom annotation 
    @interface customAnnotation : NSObject <MKAnnotation> 
{ 
    CLLocationCoordinate2D coordinate; 
    NSString*    title; 
    NSString*    info; 
} 
@property (nonatomic, retain) NSSting *title; 
@property (nonatomic, retain) NSSting *info; 

-(id) initWithCoordinate:(CLLocationCoordinate2D)c; 
@end 

@implementation customAnnotation 
@synthesize coordinate, title, info; 
-(id) initWithCoordinate:(CLLocationCoordinate2D)c 
{ 
    coordinate = c; 
    return self; 
} 
-(void)dealloc{//dealloc stuff here} 
@end 
+0

더 많은 특수 효과를 추가하려면 - (void) addAnnotation : (id ) annotation을 사용한다고 가정합니다. 몇 가지 코드를 살펴 보겠습니다. –

+0

주석을 추가하는 방법을 보여주는 코드가 추가되었습니다. – Dave

+1

문서가 성능상의 이유로 모든 주석을 즉시 추가하므로 일부 이벤트 (예 : 스크롤)가 발생할 때까지 다시 그리기를 시도하지 않을 수도 있습니다. 주석을 추가 한 후지도보기에서 setNeedsLayout을 호출하면 특수 효과의 주석을 다시 레이아웃하고 즉시 대리자 메소드를 호출 할 수 있는지 확인하십시오. –

답변

1

이는 알림을 수신 한 후 주석 핀을 추가하는 것과 관련이 있습니다. 주 스레드를 사용하여 강제로 주석 핀을 추가해야합니다.

4

그냥 확인하고 싶습니다. 나는 스레드에서 주석을 추가하고 있습니다. 내가 사용하면 이

[self performSelectorOnMainThread:@selector(addCameraIconOnMain:) withObject:cd waitUntilDone:true];  

는 일 (addCameraIconOnMain 내 annoations 추가)! 감사!

0

제 경우에는지도 위임 전에 주석을 추가하고있었습니다. 다음과 같은 형식이어야합니다 :

- (void)viewDidLoad 
{ 
    ... 

    // map delegate 
    [mView setDelegate:self]; 

    ... 

    // add annotation 
    [_map addAnnotation:_poiAnnotation]; 

    ... 
}