2009-09-22 35 views

回答

1

UICallout視圖是MKAnnotationView的子視圖。所以,我想如果你將Map ping帶到前面,UICAlloutView也會在那裏。

+0

你怎麼把UICalloutView到前面編程? – si28719e 2010-06-17 04:21:49

2

如果您正在使用自定義註釋視圖,則可以爲所選屬性添加一個觀察者,該選擇屬性將在選擇該對象時充當代表的角色。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{ 
    MKAnnotation *annview = ...code to either dequeue or create new object... 
    [annview addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:@"selectedmapannotation"];    
    return annview; 
} 

那麼你就可以

- (void)observeValueForKeyPath:(NSString *)keyPath 
        ofObject:(id)object 
        change:(NSDictionary *)change 
        context:(void *)context; 

監測選擇的狀態由Mugunth庫馬爾聯答案也會給你所期望的結果,它只是你做代表提到像你的問題的功能。

編輯:

這裏的observeValueForKeyPath的內容的例子:ofObject變化:context:方法

NSString *action = (NSString*)context; 

if([action isEqualToString:@"selectedmapannotation"]){ 
    BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue]; 
    MKAnnotationView *ann = (MKAnnotationView *)object; 

    if (annotationAppeared) { 
     // do something with the annotation when it is selected 
    } 
    else { 
     // do something with the annotation when it is de-selected 
    } 
} 
+0

能否詳細說明一下? observeValueForKeyPath實現將如何實現?你能給個例子嗎? – si28719e 2010-06-18 13:18:37

+0

編輯答案添加一個示例實現,希望有所幫助! – acqu13sce 2010-06-21 05:22:58

相關問題