質問

I need to display near by hospital details in custom view . When i tap annotation pin it displays address in custom view but whenever tapping another pin it shows same address in custom view.I tried the below code for this. Thanks in advance.

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view      calloutAccessoryControlTapped:(UIControl *)control
{
    name=[place objectForKey:@"name"];
    vicinity =[place objectForKey:@"vicinity"];


    self.myModalView = [[UIView alloc] initWithFrame:CGRectMake(0, 59, 320, 300)] ;

    [self.view addSubview:self.myModalView];
    [self.myModalView setBackgroundColor:[UIColor whiteColor]];
    [self.myModalView setBackgroundColor:[UIColor redColor]];
    self.btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.btn addTarget:self
                  action:@selector(back:)
        forControlEvents:UIControlEventTouchUpInside];
    [self.btn setTitle:@"Dismiss" forState:UIControlStateNormal];
    self.btn.frame = CGRectMake(0, 30, 80, 30);
    [self.myModalView addSubview:self.btn];

    _lblName=[[UILabel alloc]initWithFrame:CGRectMake(20, 120, 280, 60)];
    self.lblName.numberOfLines=5;

    self.lblName.text=name;
    NSLog(@"%@",self.lblName.text);
    [self.myModalView addSubview:_lblName];

    _lblDes=[[UILabel alloc]initWithFrame:CGRectMake(20, 200, 280, 80)];
    self.lblDes.numberOfLines=5;
    self.lblDes.text=vicinity;
    [self.myModalView addSubview:_lblDes];

}
役に立ちましたか?

解決

You should use that to custom your annotationView:

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

and work with the callout :

@property (retain, nonatomic) UIView *rightCalloutAccessoryView;
@property (retain, nonatomic) UIView *leftCalloutAccessoryView;

Hope that will help

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top