0

在此处输入图像描述

嗨,我需要在 MKMapAnnotationView 中实现下一个和上一个功能,如图所示。我从这里获得了用于制作自定义注释的参考,但是如何通过单击下一个和上一个按钮来更改下一个或上一个注释。请提供一些提示或关于这个的想法。我在这一点上是堆栈。

4

1 回答 1

0

为此,您可以使用rightCalloutAccessoryViewand leftCalloutAccessoryView

这是一个如何使用的示例rightCalloutAccessoryView

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

 if ([annotation isKindOfClass: [MKUserLocation class]]) {
    return nil;
}

static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];

[pinView setCanShowCallout:YES];
if([annotation isKindOfClass:[ASPinAnnotation class]])
{
    [pinView setPinColor:MKPinAnnotationColorRed];
}
else if([annotation isKindOfClass:[ASAddAutomatPin class]])
{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:[annotation title] forState:UIControlStateNormal];
    [pinView setRightCalloutAccessoryView:rightButton];
    [pinView setPinColor:MKPinAnnotationColorPurple];
}

并且要在点击 calloutAccessoryView 时获得通知,您必须在您的委托中使用此功能:

   -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
   {

if([(UIButton*)control buttonType] == UIButtonTypeDetailDisclosure)
{
    ASAddViewController *addController = [[ASAddViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addController];
    [addController setDelegate:self];
    [self.controller presentViewController:navController animated:YES completion:nil];
}

}
于 2013-01-08T20:47:03.953 回答