0

到目前为止,我的情节提要中有一个 DetailViewController ,没有转接/转接。这是我在地图视图控制器中的代码...

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

如何做到这一点,以便在按下呼叫时显示我的详细视图控制器?

4

2 回答 2

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委托并确保调用此委托方法。

希望这可以帮助

于 2014-08-17T00:20:27.807 回答
0

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

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

这对我有用

于 2014-08-17T16:38:01.050 回答