the problem is this:
I have a mapkit view with 2 different colors pinpoint. Now i have added in a segmented control to display different map types ie. satellite, standard and hybrid. When my application loads, its correct with 2 different colors. However, when i select the segments, all my pinpoints will change to red colour.
Is there a way to reload all my data and pinpoints such that every segment will give me 开发者_StackOverflowthe same initial view??
- (IBAction) segmentAction:(id)sender
{
UISegmentedControl* segCtl = sender ;
if( [segCtl selectedSegmentIndex] == 0 )
{
NSLog(@"first view");
_mapView.mapType=MKMapTypeStandard;
}
if( [segCtl selectedSegmentIndex] == 1 )
{
NSLog(@"2nd view");
_mapView.mapType=MKMapTypeSatellite;
}
if( [segCtl selectedSegmentIndex] == 2 )
{
NSLog(@"3rd view");
_mapView.mapType=MKMapTypeHybrid;
}
}
Make sure your map view controller implements the viewForAnnotation: method - if this is missing, the pin colors might get reset if the view is refreshed. For example:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView *newAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"redpin"] autorelease];
newAnnotation.pinColor = MKPinAnnotationColorRed;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES;
return newAnnotation;
}
精彩评论