Nếu bạn đang sử dụng chế độ xem chú thích tùy chỉnh, bạn có thể thêm người quan sát cho thuộc tính đã chọn sẽ hoạt động như một đại biểu cho thời điểm ghim được chọn.
- (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;
}
sau đó bạn có thể theo dõi tình trạng chọn với
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context;
Câu trả lời được liên kết bởi Mugunth Kumar cũng sẽ cung cấp cho bạn những kết quả mong muốn nó chỉ là bạn đã thực hiện đề cập đến đại biểu như chức năng trong câu hỏi của bạn.
EDIT:
Dưới đây là một ví dụ về các nội dung của observeValueForKeyPath: ofObject: thay đổi: bối cảnh: Phương pháp
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
}
}
làm thế nào để bạn mang UICalloutView vào phía trước lập trình? – si28719e