Loading

Sunday, June 27, 2010

Map View Delegate Methods

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
MKAnnotationView *tmp=[[MKAnnotationView alloc]initWithFrame:CGRectMake(10,10,30,30)];
tmp.image=[UIImage imageNamed:[NSString stringWithFormat:@"Pin.png"]];
[tmp addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:@"selectedmapannotation"];
return tmp;

}


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

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

if (annotationAppeared)
{
NSLog(@"Wow it's Selected :-) ");
}
else
{
NSLog(@"Opps it's Not Selected :-( ");
}
}
}

No comments:

Post a Comment