如何使用下一个和上一个功能自定义MKMapview注释?

时间:2013-01-08 20:11:29

标签: objective-c annotations mkmapview mkannotationview

enter image description here

HI我要求在MKMapAnnotationView中实现Next和Previous功能,如图所示。我已经从Here获得了用于进行自定义注释的引用但是如何通过单击Next和更改下一个或上一个注释上一个按钮。请提供一些关于此的提示或想法。我现在正在堆叠。

1 个答案:

答案 0 :(得分:0)

为此,您可以使用rightCalloutAccessoryViewleftCalloutAccessoryView

以下是如何使用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];
}

}