简体   繁体   中英

How do I make my annotation callout lead to a different view controller?

I appreciate all answers. Thank you so much for your time. I've looked for awhile but can't find a solution to my problem...

I let the restaurant user set a pin that includes the restaurant picture, a text title (they write this right before they set the pin), a text subtitle (they write this right before they set the pin), and a info button callout.

I want to make it so that when the user presses the info button callout, he/she is brought to a page that displays the restaurant picture, the restaurant name, the title, subtitle, and name. Also I need there to be a back button that brings the user right back to the map view in the first view controller.

So there will be numerous different restaurants and I need to somehow get the data from the first view controller's pin to the second view controller.

I currently have this code in my first view controller to display the annotations

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:    (id<MKAnnotation>)annotation {

if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;
MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"User"];


UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:nil action:nil forControlEvents:UIControlEventTouchUpInside];
MyPin.rightCalloutAccessoryView = rightButton;
MyPin.draggable = NO;
MyPin.highlighted = YES;
MyPin.animatesDrop=TRUE;
MyPin.canShowCallout = YES;
UIImageView *myCustomImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CorgiRunner2 Final.png"]];
myCustomImage.image = profPic;
myCustomImage.frame = CGRectMake(0,0,31,31);
MyPin.leftCalloutAccessoryView = myCustomImage;

return MyPin;
}

What do I have to do to display a restaurant's specific info after the callout in the first view controller is pressed? Also, remember I somehow need access to the text in the first view controller.

Again, thank you in advance!

  1. Create a subclass of MKAnnotation that has a restaurant property.
  2. When the button is tapped, it should call -mapView:annotationView:calloutAccessoryControlTapped: . You can then use annotationView.annotation.restaurant to know what restaurant you have. You can tell it to present the next view controller here and pass along that restaurant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM