当注释拍了拍MapView的数据传递到的DetailView [英] Pass data to detailView when annotation tapped on mapview

查看:122
本文介绍了当注释拍了拍MapView的数据传递到的DetailView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个地图视图和有通过Web服务的数据来自10店址。我只是想推到我的详细信息视图显示的地址,电话和点击商店的其它信息。

I have a map view and there are 10 store locations which data comes via webservice. I just want to push to my detail view to show address, telephone and other informations of the clicked store.

我需要将数据传递到我的的DetailView 当用户窃听或内部触摸到一个注解上mapkit。有我在 10 MapView类注释键,首先我要知道,我怎么能理解或者我怎样才能得到它的点击注解annotationID?

I need to pass data to my detailview when user tapped or touch up inside to a annotation on mapkit. There are 10 annotations in my mapview and first I want to know, how can I understand or how can I get the annotationID of which annotation is clicked?

这是我回到引脚的方法

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

 }

如果我可以获取单击批注指数无我可以用我的数组填写详细属性。
如果这是不可能有任何其他的方式做到这一点?

if i can just get the clicked annotation index no i can fill detail properties with my array. if this is impossible is there any other way to do it?

推荐答案

首先在你的annotaion视图delegat做一个按钮,在详细信息视图去像波纹管:

First in your annotaion view delegat make a button to go in detail view like bellow:

-(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按钮将得到窃听以下代表将被称为从那里你可以得到伊斯利哪个特定的annotaion的按钮被窃听

Now use the following delegate whenever the button in annotationView will get tapped the following delegate will be called from where you can easly get which particular annotaion's button is tapped

- (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和地址和PHONENUMBER都可以使更多的,同时的DetailView类的地址和PhoneNumber属性强annotaion类的属性。所以,你可以传递值。希望这会帮助你的!

here annotaion is a class importing MKAnnotaion.h and address and phonenumber are properties of annotaion class you can make many more while the address and phoneNumber properties of detailView class are strong. So that you can pass values. Hope this will help you!

这篇关于当注释拍了拍MapView的数据传递到的DetailView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆