Custom action
Hi, I'm using the ZSPinAnnotation on my map (which helps me a lot!) but I'm trying to set a custom action to each pin and I can't seem to get an ID or tag from each pin, have you done this?
You should be able to set your own tag easily. Can you show me the code you are trying to use?
On May 27, 2014, at 11:22 AM, melisadlg [email protected] wrote:
Hi, I'm using the ZSPinAnnotation on my map (which helps me a lot!) but I'm trying to set a custom action to each pin and I can't seem to get an ID or tag from each pin, have you done this?
— Reply to this email directly or view it on GitHub.
-
(void)loadPinsParques {
NSMutableArray *annotationArray = [[NSMutableArray alloc] init];
ZSAnnotation *annotation = nil;
annotation = [[ZSAnnotation alloc] init]; annotation.coordinate = CLLocationCoordinate2DMake(25.644416, -100.328359); annotation.type = ZSPinAnnotationTypeTag; annotation.color = RGB(182, 154, 0); annotation.title = @"Parque Rufino Tamayo"; annotation.tag = 9; [annotationArray addObject:annotation];
annotation = [[ZSAnnotation alloc] init]; annotation.coordinate = CLLocationCoordinate2DMake(25.617705, -100.359368); annotation.type = ZSPinAnnotationTypeTag; annotation.color = RGB(182, 154, 0); annotation.title = @"Parque Ecológico Chipinque"; annotation.tag = 10; [annotationArray addObject:annotation];
// Add to map[self.mapView addAnnotations:annotationArray]; // Center map self.mapView.visibleMapRect = [self makeMapRectWithAnnotations:annotationArray];
}
-
(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation {
// Don't mess with user locationif(![annotation isKindOfClass:[ZSAnnotation class]]) return nil;
ZSAnnotation *a = (ZSAnnotation *)annotation; static NSString *defaultPinID = @"StandardIdentifier";
// Create the ZSPinAnnotation object and reuse itZSPinAnnotation *pinView = (ZSPinAnnotation *)[mV dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil){ pinView = [[ZSPinAnnotation alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID]; }
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; [button setImage:[UIImage imageNamed:@"boton_info.png"] forState:UIControlStateNormal]; pinView.rightCalloutAccessoryView = button; [button addTarget:nil action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside]; [pinView setEnabled:YES]; pinView.annotationType = ZSPinAnnotationTypeTag; pinView.annotationColor = a.color; pinView.canShowCallout = YES;
return pinView;
}
-
(void) showDetails:(ZSAnnotation *)annotation{
[UIView animateWithDuration:0.7 animations:^{ [detailView setFrame:CGRectMake(0, 68, 1024, 700)]; closeBTN.alpha = 1.0; } completion:^(BOOL finished){ }];
if (annotation.tag == 9) {
[detailName setText:@"Plaza Rufino Tamayo"]; [detailGiro setText:@"Parque"]; [detailDescri setText:@"Cupcake ipsum dolor. Sit amet fruitcake pudding. Icing ice cream cupcake chocolate bar brownie. I love toffee cotton candy tart. I love lemon drops applicake."];}
else if (annotation.tag == 10) {
[detailName setText:@"Plaza Ecologico Chipinque"]; [detailGiro setText:@"Parque"]; [detailDescri setText:@"Liquorice sesame snaps candy. Candy lemon drops jujubes.\nBear claw brownie sugar plum pudding bear claw carrot cake brownie candy canes. I love bonbon unerdwear.com toffee pie powder. Dessert halvah fruitcake. Ice cream unerdwear.com I love lollipop. Unerdwear.com macaroon dragée sweet. Topping dragée dragée."];}
}
In your showDetails: method you should be just getting the text and description directly from the ZSAnnotation object rather then setting it manually. There shouldn't be any need for tags or conditional statements.