viewForAnnotation not called in iPhone 4 but works in simulator [closed]
So I am having the strangest problem and I have gone to every where it seem. What I am having an issue with is that I create custom annotation views for my MKMapView.This MKMapView starts with no annotations and as you change the region then annotation are created and added to the map. Upon calling [my_map_view addAnnotation:a_annotation]; Nothing happens. mapView viewForAnnotation is not called and there is nothing Displayed. Now, this is the case for the iPhone4 however when I run the same code on the simulator it ends up working. I am wondering why this is? I believe that it is a refresh开发者_开发知识库 problem on the maps part because when I double tap on the phone and the map does its zoom deal, the annotation shows up. I know that you can do a whole bunch of [my_map_view setRegion:my_map_view.currentRegion]; and setting the center with its center to try a refresh I have even tried changing the region to a different one however nothing works. Any Ideas, I am stumped and have been working on this for the past 3 days.
Hey guys so I fixed what the issue is. Whenever you have a problem reloading the map I found the best solution is to destroy and create the map in order to show your annotations. So make sure to remove the map from the view release it set it to nil and then reallocate the memory and initialize it with you annotation data. Sorry about not posting code I have to clean a lot of the data names in order to:( - If this solution doesnt work go ahead and shoot me a message so I can go through the code with you. If anything I can always make an example for you:) it just might be a while cause of work.
Also here is my view for annot method for you guys cause I know that that was wanted for posting :)
-(MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKAnnotationView *annotation_view = nil;
CustomAnnotation *annot = (CustomAnnotation*)annotation;
CustomAnnotationView *view;
view = [[[CustomAnnotationView alloc] initWithAnnotation:annot reuseIdentifier:@"Job"] autorelease];
[view addObserver:self forKeyPath:@"selected"options:NSKeyValueObservingOptionNew context:GMAP_ANNOTATION_SELECTED];
view.image = [UIImage imageNamed:@"map_marker"];
view.canShowCallout = YES;
annotation_view = view;
[annotation_view setEnabled:YES];
[annotation_view setCanShowCallout:YES];
return annotation_view;
}
精彩评论