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

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

我需要传递数据到我的detailview当用户点击或触摸内部的mapkit注释。 在我的mapview有10个注释,首先我想知道,我怎么能理解,或者怎样才能得到注释被点击的annotationID?

这是我返回引脚的方法

  - (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]; } 

如果我可以得到点击注释索引号我可以用我的数组填充细节属性。 如果这是不可能的,有没有其他办法可以做到这一点?

首先在你的annotaion视图中,delegat做一个button,如下图所示:

 -(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; } 

现在使用下面的委托,只要annotationView中的button将被挖掘下面的委托将被调用从哪里你可以很容易得到哪个特定的注释button被挖掘

 - (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]; } 

这里的annotaion是一个导入MKAnnotaion.h的类,地址和电话号码是annotaion类的属性,你可以做更多,而detailView类的地址和phoneNumber属性强。 所以你可以传递值。 希望对你有帮助!

贝娄是MapView委托方法……

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

当用户点击注释引脚上面的方法调用automaticaly时,如果方法定义在.m文件中,首先在.h文件中声明MKMapViewDelegate委托

也可以从谷歌的地方API获得标题或字幕和ID ….链接是… https://developers.google.com/maps/documentation/places/

 for(int i=0; i<[arrLat count];i++) { CLLocationCoordinate2D theCoordinate1; konumpin* myAnnotation1=[[konumpin alloc] init]; theCoordinate1.latitude = [[arrLong objectAtIndex:i] doubleValue]; theCoordinate1.longitude = [[arrLat objectAtIndex:i] doubleValue]; myAnnotation1.coordinate=theCoordinate1; myAnnotation1.title=[arrMagaza objectAtIndex:i]; [annotations addObject:myAnnotation1]; } [mtMap addAnnotations:annotations];