1

我正在尝试找到一种方法让多个注释披露按钮打开其他视图。例如,annotation1 披露按钮需要打开 ViewController 1.xib,annotation2 需要打开 ViewController2.xib,以此类推。这可能吗?

到目前为止,我已经有了这段代码,它根据坐标设置位置,并设置用户位置。

- (void)viewDidLoad
{
[super viewDidLoad];
_mapView.showsUserLocation = YES;
CLLocationCoordinate2D annotationCoord;

annotationCoord.latitude = 40.714353;
annotationCoord.longitude = -74.005973;
coord = 1;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = @"New York";
[_mapView addAnnotation:annotationPoint];

CLLocationCoordinate2D annotationCoord1;

annotationCoord1.latitude = 51.511214;
annotationCoord1.longitude = -0.119824;
coord = 2;
MKPointAnnotation *annotationPoint1 = [[MKPointAnnotation alloc] init];
annotationPoint1.coordinate = annotationCoord1;
annotationPoint1.title = @"London";
[_mapView addAnnotation:annotationPoint1];
}

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *mapPin = nil;
if(annotation != map.userLocation)
{
    static NSString *defaultPinID = @"defaultPin";
    mapPin = (MKPinAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if (mapPin == nil )
    {
        mapPin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation
                                                  reuseIdentifier:defaultPinID] autorelease];
        mapPin.canShowCallout = YES;
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        mapPin.rightCalloutAccessoryView = infoButton;
    }
    else
        mapPin.annotation = annotation;

}
return mapPin;
}

我在这里放什么:

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

感谢所有帮助。谢谢

4

1 回答 1

1

你可以做这样的事情,

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
  if ([view.annotation.title isEqualToString:@"The titel of your annotation"]) 
  {
    // Do something
  }
}   
于 2014-10-18T00:16:04.483 回答