Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom action #9

Open
melisadlg opened this issue May 27, 2014 · 3 comments
Open

Custom action #9

melisadlg opened this issue May 27, 2014 · 3 comments

Comments

@melisadlg
Copy link

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?

@nnhubbard
Copy link
Owner

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.

@melisadlg
Copy link
Author

  • (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 )annotation {

    // Don't mess with user location
    

    if(![annotation isKindOfClass:[ZSAnnotation class]])
    return nil;

    ZSAnnotation *a = (ZSAnnotation *)annotation;
    static NSString *defaultPinID = @"StandardIdentifier";

    // Create the ZSPinAnnotation object and reuse it
    

    ZSPinAnnotation *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."];
    

    }

}

@nnhubbard
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants