如何使我的注释标注引导到新的视图控制器?

时间:2014-08-16 22:43:17

标签: ios objective-c annotations callout

截至目前,我的故事板中有一个DetailViewController,没有来自/来自的segue。这是我在地图视图控制器中的代码......

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

如何制作它,以便在按下调出时,我的Detail View Controller显示?

2 个答案:

答案 0 :(得分:0)

像这样使用calloutAccessoryControlTapped

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

不要忘记设置mapView个委托,并确保调用此委托方法。

希望这有帮助

答案 1 :(得分:0)

UPDATE 我将mapView连接到主故事板中的DetailView控制器,并使用

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

这适用于我