MKAnnotation - A card tip output pops up for other map pins

My card contacts can be quite tightly populated, so when a pin is selected, a pop-up window will be displayed, but basically it will be hidden from all other card contacts. I can bring the Pin card to the foreground, there was a delegate for the selected pin card (not inverted callout, selected contact).

Any job offers?

+7
iphone
source share
2 answers

If you use custom annotation views, you can add an observer for the selected property, which will act as a delegate when the contact is selected.

- (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; } 

then you can control the selected state with

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

The answer related to Mugunth Kumar will also give you the desired results, you just mentioned delegation as a function in your question.

EDIT:

Here is an example of the contents of a watch function: VALUEForKeyPath: ofObject: change: context: method

 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 } } 
+2
source share

UICallout view is a subclause of MKAnnotationView. So, I think that if you come Map ping to the front, UICAlloutView will be there too.

+1
source share

All Articles