Is it possible to display a View controller with further details of the Map annotation on a new view controller which when popped returns back to the MKMap view with the annotations still on it at that position. I can't seem to find a way in the SDK documentation that seems to indicate that its possible.
+2
A:
Found the answer to my own question if you do the following:
What you can do is use an observer instead so in the
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
method you can add the code like this:
//Add an observer for the selected-property on the MKAnnotationView. Delegate to self.
[annotationView addObserver:self
forKeyPath:@"selected"
options:NSKeyValueObservingOptionNew
context:GMAP_ANNOTATION_SELECTED];
annotationView.annotation = annotation;
annotationView.canShowCallout = NO;
then create an observer catch which will call the method to render whatever view when the user clicks the annotation on the screen:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context{
NSString *action = (NSString*)context;
if([action isEqualToString:GMAP_ANNOTATION_SELECTED]){
BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
if (annotationAppeared) {
[self showAnnotation:((AssetAnnotationView*) object).annotation];
}
else {
//NSLog(@"annotation deselected %@", ((AssetAnnotationView*) object).annotation.title);
//[self hideAnnotation];
}
}
}
then have your method which displays a modal view or whatever you want:
- (void)showAnnotation:(AssetAnnotationView*)annotation {
UINavigationController *aNavController = [[UINavigationController alloc] initWithRootViewController:self.assetInfoViewController];
aNavController.navigationBar.barStyle = UIBarStyleBlack;
[self presentModalViewController:aNavController animated:YES];
[aNavController release];
}
Unselect in viewWillAppear:
NSArray *selected = [localMapView selectedAnnotations]; for(id annotation in selected) { [localMapView deselectAnnotation:annotation animated:NO]; }
vladzz
2010-04-11 01:02:57
make sure you unselect the annotaiton in your viewDidAppear/viewWillAppear otherwise you will get into the same problem as me and not be able to select the annotation again.
vladzz
2010-06-21 09:34:08
And how do you unselect the annotation? I'm trying here with no success.
goo
2010-08-05 00:01:02
Not the most efficient way of doing this. But this method seems to work. NSArray *selected = [localMapView selectedAnnotations]; for(id<MKAnnotation> annotation in selected) { [localMapView deselectAnnotation:annotation animated:NO]; }
vladzz
2010-08-06 23:19:50
A:
You can also use a tag for every annotation you create. Works for me.
alecnash
2010-06-06 02:51:24