1

I was wondering if there is any way to add a UITextField & a UIButton in MKPinAnnotationView callout bubble and in turn if the user clicked button it will call some method?

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

you can add your custom view instead of MKAnnotationView with bellow code..

you can simple add any control with addSubview property...

-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation 
{
    MKAnnotationView *customPinView = nil; 
    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( customPinView == nil ) 
            customPinView = [[MKAnnotationView alloc]
                                         initWithAnnotation:annotation reuseIdentifier:defaultPinID];

        customPinView.canShowCallout = YES;
        //customPinView.animatesDrop = YES;
        customPinView.image = [UIImage imageNamed:@"yourImageName"];//write your imagename 
        // and add UIButton with bellow code
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self
                            action:@selector(ShowStoreDetail:)
                  forControlEvents:UIControlEventTouchUpInside];
        customPinView.rightCalloutAccessoryView = rightButton;here
    } 
    else {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

i hope it is useful to you...

:)

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70