【问题标题】:Set different actions for different annotations in MKMapView在 MKMapView 中为不同的注解设置不同的动作
【发布时间】:2013-04-26 01:02:45
【问题描述】:

我正在尝试找到一种方法让多个注释披露按钮打开其他视图。 例如,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
{
//   ???
}

感谢所有帮助。谢谢

【问题讨论】:

    标签: xcode annotations location mkmapview disclosure


    【解决方案1】:

    你可以这样做,

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
      if ([view.annotation.title isEqualToString:@"The titel of your annotation"]) 
      {
        // Do something
      }
    }   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 2014-03-08
      相关资源
      最近更新 更多