在mapview上点击注释时,将数据传递给detailView

erc*_*can 3 iphone annotations mkmapview ios

我有一个地图视图,有10个商店位置,数据来自webservice.我只想推送到我的详细视图,以显示点击的商店的地址,电话和其他信息.

detailview当用户点击或在内部触摸到mapkit上的注释时,我需要将数据传递给我.在我mapview和我想知道的第一个中有10个注释,我如何理解或如何获得单击注释的注释ID?

这是我返回引脚的方法

 - (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.animatesDrop=YES;
     pinView.canShowCallout=YES;
     pinView.pinColor=MKPinAnnotationColorPurple;

     UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
     [rightButton setTitle:annotation.title forState:UIControlStateNormal];

     [rightButton addTarget:self
     action:@selector(showDetails:)
     forControlEvents:UIControlEventTouchUpInside];

     pinView.rightCalloutAccessoryView = rightButton;

    return pinView;
}
   /* and my action method for clicked or tapped annotation: */

 - (IBAction)showDetails:(id)sender{

      NSLog(@"Annotation Click");

      [[mtMap selectedAnnotations]objectAtIndex:0];
      magazaDetayViewController *detail = [[magazaDetayViewController 
      alloc]initWithNibName:@"magazaDetayViewController" bundle:nil];

      detail.sehir=@"";
      detail.magazaAdi=@"";
      detail.adres=@"";
      detail.telefon=@"";
      detail.fax=@"";
      [self.navigationController pushViewController:detail animated:YES];

 }
Run Code Online (Sandbox Code Playgroud)

如果我能得到点击的注释索引,我可以用我的数组填充详细属性.如果这是不可能的,还有其他办法吗?

sup*_*kuN 9

首先在你的注释视图中,委托制作一个按钮,进入详细视图,如下:

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

MKPinAnnotationView *mypin = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"current"];
mypin.pinColor = MKPinAnnotationColorPurple;
mypin.backgroundColor = [UIColor clearColor];
UIButton *goToDetail = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
mypin.rightCalloutAccessoryView = myBtn;
mypin.draggable = NO;
mypin.highlighted = YES;
mypin.animatesDrop = TRUE;
mypin.canShowCallout = YES;
return mypin;
}
Run Code Online (Sandbox Code Playgroud)

现在使用以下委托,只要annotationView中的按钮被点击,将调用以下委托,您可以从中轻松获取哪个特定的注释按钮被点击

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
 calloutAccessoryControlTapped:(UIControl *)control
{
annotation *annView = view.annotation;
detailedViewOfList *detailView = [[detailedViewOfList alloc]init];
detailView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
detailView.address = annView.address;
detailView.phoneNumber = annView.phonenumber;
[self presentModalViewController:detailView animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

这里的注释是一个导入MKAnnotaion.h的类,地址和语音是注释类的属性,你可以做更多,而detailView类的地址和phoneNumber属性很强.这样你就可以传递价值.希望对你有帮助!