0

As of now, I have a DetailViewController in my storyboard with no segues to/from. Here is my code in the map view controller...

-(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;

[rightButton addTarget:self action:@selector(pinTouched:) forControlEvents:UIControlEventTouchUpInside];

return MyPin;
}




-(void)pinTouched:(UIButton *)sender
{
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];

detailViewController.profName1 = profName;
detailViewController.profPic1 = profPic;
}

How do I make it so that when the call out is pressed, my Detail View Controller shows up?

  • Just a note: All your questions so far have already been asked and answered several times by other users on SO. Please search thoroughly on SO, the documentation, and elsewhere before posting potentially duplicate questions (and re-posting your own questions again is not a good approach either -- edit your existing question instead and explain why the posted answer didn't work for you). –  Aug 17 '14 at 12:22
  • For your current question, see http://stackoverflow.com/questions/14805954/mkannotationview-push-to-view-controller-when-detaildesclosure-button-is-clicked for an example. –  Aug 17 '14 at 12:24
  • By the way, don't use addTarget if you're going to use the built-in delegate method calloutAccessoryControlTapped. The map view will call its delegate method automatically if you set the accessory view and its delegate is set. –  Aug 17 '14 at 12:28

2 Answers2

0

Use calloutAccessoryControlTapped like this:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"tapped");
    DetailViewController *detailViewController = [[DetailViewController alloc]     initWithNibName:@"DetailViewController" bundle:nil];

    detailViewController.profName1 = profName;
    detailViewController.profPic1 = profPic;
}

Don't forget to set your mapView delegates and make sure this delegate method gets called.

Hope this helps

Ty Lertwichaiworawit
  • 2,950
  • 2
  • 23
  • 42
0

UPDATE I instead connected my mapView to my DetailView Controller in the main storyboard, and used

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[self performSegueWithIdentifier:@"Details" sender:view];
}

THIS WORKS FOR ME