1

Possible Duplicate:
MKPinannotation detail disclosure button - present new view

Would any one lemme know how do i get an accessory button (Detail Disclosure) on a map pin and have some event on its click event. Thank you

Community
  • 1
  • 1

2 Answers2

3

You can add accessory button to your pin using:

yourPinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

When you click on accessory button this delegate will be invoked:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
            calloutAccessoryControlTapped:(UIControl *)control
{
   //do your stuff here
}
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
  • @MidhunMP and paras...hey i got the disclosure button but i want that on its click event it should navigate to a web page i.e if the pin is on pune when i clik it it should navigate to wikipedia displaying pune 's information... plzz help out – iMNavedShaikh Jan 09 '13 at 06:19
  • @iMNavedShaikh: The `calloutAccessoryControlTapped` will work when you tap on the accessory button. You can load your webpage and other sruffs there. Set your mapview's delegate to self. Then implement the above delegate method. – Midhun MP Jan 09 '13 at 06:22
  • so would i need to add a new file for the web page @MidhunMP – iMNavedShaikh Jan 09 '13 at 06:26
  • @iMNavedShaikh: If you need to do that, you need to add a new page and create a web view on it and present it modally. Another option is to open that in safari using url loading scheme – Midhun MP Jan 09 '13 at 06:30
  • i did it by adding a new file and i import its class and creted its object in the mapview class. Now the thing is where do i write the code for switch i.e pass the url to the prop i created in new web file. coz my mapview file doesnt hav a did select row at index method.. – iMNavedShaikh Jan 09 '13 at 06:34
  • @iMNavedShaikh: I'm already mentioned you that, when you click on the accessory button the `calloutAccessoryControlTapped` method is invoked. Check my answer too. You can present a modal view controller from that method. – Midhun MP Jan 09 '13 at 06:37
  • kkk...letme chk it... @MidhunMP – iMNavedShaikh Jan 09 '13 at 06:40
  • @iMNavedShaikh: ok, please check it, if you stuck anywhere please tell me. – Midhun MP Jan 09 '13 at 06:42
  • kkk if i dont get it i will mail you.. @MidhunMP – iMNavedShaikh Jan 09 '13 at 06:44
  • hey don wid it...but would you letme know that suppose if i have 2 pins 1on mumbai nd other on pune wid the del mthd i can navigate it to web but hw do we do it for other pin coz it shud show mumbais web..and switch isnt wrking.. – iMNavedShaikh Jan 09 '13 at 08:40
  • @iMNavedShaikh: you need to add a tag for each pin view. When you click it, check the tag in that delegate method like if(view.tag == 1) – Midhun MP Jan 09 '13 at 08:51
  • i tried using tag but wer we need to assign the tag.. – iMNavedShaikh Jan 09 '13 at 08:55
  • For this you need to implement the `viewForAnnotation` delegate method. – Midhun MP Jan 09 '13 at 08:56
  • yeah i did dat..wait il mail u the code of it..is it obk @MidhunMP – iMNavedShaikh Jan 09 '13 at 09:01
0

If you want some different then do

        UIButton *DetailViewBtn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        DetailViewBtn.tag = currentAnnotation.tag;

        [DetailViewBtn setTitle:currentAnnotation.title forState:UIControlStateNormal];
        [DetailViewBtn addTarget:self
                        action:@selector(annotationBtnPress:)
              forControlEvents:UIControlEventTouchUpInside];

        yourAnnotationView.rightCalloutAccessoryView = DetailViewBtn;  

and your method here

-(IBAction)annotationBtnPress:(id)sender
{
    NSLog(@"raj");
}
Rajneesh071
  • 30,846
  • 15
  • 61
  • 74