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

Iphone 在mapview上点击注释时将数据传递给detailView,iphone,ios,annotations,mkmapview,Iphone,Ios,Annotations,Mkmapview,我有一个地图视图,有10个存储位置,数据通过webservice提供。我只想推到我的详细视图,以显示地址,电话和其他信息的点击商店 当用户点击mapkit上的注释或在其内部进行润色时,我需要将数据传递到我的detailview。mymapview中有10个注释,首先我想知道,如何理解或如何获取单击注释的注释ID 这是我返回引脚的方法 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAn

我有一个地图视图,有10个存储位置,数据通过webservice提供。我只想推到我的详细视图,以显示地址,电话和其他信息的点击商店

当用户点击mapkit上的注释或在其内部进行润色时,我需要将数据传递到我的
detailview
。my
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];

 }
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
if([annotation isKindOfClass:[MKUserLocation class]])返回nil;
静态NSString*AnnotationIdentifier=@“AnnotationIdentifier”;
MKPinAnnotationView*pinView=[[MKPinAnnotationView alloc]initWithAnnotation:annotation重用标识符:AnnotationIdentifier];
pinView.animatesDrop=是;
pinView.canShowCallout=是;
pinView.pinColor=MKPinAnnotationColorPurple;
UIButton*rightButton=[UIButton Button类型:UIButtonTypedTailButton];
[rightButton setTitle:annotation.title for状态:UIControlStateNormal];
[rightButton添加目标:自我
操作:@选择器(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView=rightButton;
返回pinView;
}
/*以及单击或点击注释的我的操作方法:*/
-(iAction)显示详细信息:(id)发件人{
NSLog(@“注释点击”);
[[mtMap selectedAnnotations]对象索引:0];
magazaDetayViewController*详细信息=[[magazaDetayViewController]
alloc]initWithNibName:@“magazaDetayViewController”捆绑包:nil];
detail.sehir=@;
详情.magazaAdi=@”;
详情.地址=@“;
详情.telefon=@“;
传真=@;
[self.navigationController pushViewController:详细动画:是];
}
如果我可以只获取单击的注释索引no,我可以用数组填充细节属性。
如果这是不可能的,还有其他方法吗?

下面是
MapView
的委托方法

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

}
当用户点击方法上方的注释pin时,自动调用.m文件中的方法定义,首先在.h文件中声明
MKMapViewDelegate
delegate

而且你也可以从GooglePlaceAPI获取标题、副标题和id。。。。 链接是。。。

首先在注释视图中删除,在细节视图中创建一个按钮,如下图所示:

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

这里的Annotation是一个导入mkAnnotation的类。h和address和phonenumber是Annotation类的属性,当detailView类的address和phonenumber属性很强时,您可以制作更多。这样就可以传递值。希望这对你有帮助

用于(int i=0;我想知道答案。我对ios非常陌生,请告诉我如何设置详细信息。地址例如,是否有此调用方法的示例应用程序或代码?当然,此链接仅返回此链接上的子站点和标题,但您可以使用上面的委托方法,而不是查看标题和副标题…Thnx获取我的详细答案一个问题:在何处以及如何填充或设置annView.address?如何在地图上获取批注?在我的viewdidload方法中(int i=0;i您的konumpin类现在是我的注释类,因为您已经在konumpin类中设置了NSString title,就像这样设置了更多的NSString,您希望在您的描述类ex NSString*phoneNumber中显示这些NSString,并将其属性设置为title。现在将您的konumpin类导入到您的描述类中,并为其创建一个对象并设置属性对于它@property(nonatomic,strong)konumpin*description注释;现在,在上面的委托中,将对象设置为您的描述类,然后执行此description class.description注释=view.annotation;这将把您的注释传递到您的描述类。如果您需要,我可以向您发送一个演示项目,请给我您的电子邮件id
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];
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];