I don't think I am understanding this correctly, I added the annotation to the map. I can see it, the color is red. However, I want to change it to purple and I want it as a button. So I put it as follows:
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
//[self generateAnnotation];
CLLocationCoordinate2D aCoordinate;
aCoordinate.latitude = 32.224023;
aCoordinate.longitude = -110.965159;
MapAnnotation * an1 = [[[MapAnnotation alloc] initWithCoordinate: aCoordinate] autorelease];
an1.title = @"Party at Malloneys";
an1.subtitle = @"213 N. 4th Ave";
//[annotationArray addObject:an1];
[mapView addAnnotation:an1];
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate=self;
self.locationManager.distanceFilter = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
}
- (void) mapView:(MKMapView *) mapView
didAddAnnotationViews:(NSArray *) views
{
for (MKPinAnnotationView * mkaview in views)
{
mkaview.pinColor = MKPinAnnotationColorPurple;
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
mkaview.rightCalloutAccessoryView = button;
}
}
- (MKAnnotationView *) mapView:(MKMapView *) mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
MKPinAnnotationView * annView = (MKPinAnnotationView*) [mapView dequeueReusableAnnotationViewWithIdentifier:@"an1"];
if (!annView)
{
annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"an1"] autorelease];
annView.pinColor = MKPinAnnotationColorGreen;
annView.animatesDrop = YES;
annView.canShowCallout = YES;
}
else {
annView.annotation = annotation;
}
return annView;
}
I don't understand the two delegates above, viewForAnnotation is supposed for setting the view for the annotation right? and the didAddAnnotationViews delegate method is executed after the view is loaded?? Please correct my understanding if this is wrong. And how can I fix this so that I can change color and add a button.