简体   繁体   English

在iPhone SDK中,如何在单击MKMapView的注释钉时切换到另一个视图?

[英]How to switch to another view on click of annotation pin in MKMapView in iPhone SDK?

1 i am using multiple pin in mkmapview and i want to display detail in next view of tapped pin 1我在mkmapview中使用多个图钉,我想在点击图钉的下一个视图中显示详细信息

#import "mapViewController.h"
#import "displaymap.h"
#import "second.h"

@implementation mapViewController
@synthesize mapview;
@synthesize selectedAnnotationsl;



- (void)viewDidLoad {
[super viewDidLoad];

[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];
MKCoordinateRegion region={{0.0,0.0},{0.0,0.0}};
region.center.latitude=22.292189;
region.center.longitude=70.792207;
region.span.longitudeDelta=0.01f;
region.span.latitudeDelta=0.01f;
[mapview setRegion:region animated:YES];


    //[mapview setDelegate:self];

displaymap *ann=[[displaymap alloc]init];
ann.title=@"alpesh";
ann.subtitle=@"Mahatma Gandhi";
ann.coordinate = region.center;
[mapview addAnnotation:ann];

region.center.latitude=22.295031;
region.center.longitude=70.790837;
region.span.longitudeDelta=0.01f;
region.span.latitudeDelta=0.01f;
displaymap *bnn=[[displaymap alloc]init];
bnn.title=@"samir";
bnn.subtitle=@"Mahatma Gandhi";
bnn.coordinate = region.center;
[mapview addAnnotation:bnn];

//selectedAnnotationsl =[[NSArray alloc]initWithObjects:bnn.title,ann.title,nil];
}


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

    if(pinView==nil)pinView=[[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPinID]autorelease];
    pinView.pinColor=MKPinAnnotationColorRed;
    pinView.canShowCallout=YES;
    pinView.animatesDrop=YES;
    pinView.calloutOffset= CGPointMake(-5, 5);
}
else
{
    [mapview.userLocation setTitle:@"I am here"];

}
return pinView;
 }




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

MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[addButton addTarget:self action:@selector(changepage:) forControlEvents:UIControlEventTouchUpInside];
[annView setPinColor:MKPinAnnotationColorRed];
annView.rightCalloutAccessoryView = addButton;
annView.animatesDrop = TRUE;
annView.canShowCallout = YES;

return annView;

}



-(IBAction)changepage:(UIView*)sender
{
second *s = [[second alloc]initWithNibName:@"second" bundle:nil];
s.title = @"samir"; 
[[self navigationController] pushViewController:s animated:YES];
}

MKMapViewDelegate's calloutAccessoryControlTapped: method is what you need. 您需要MKMapViewDelegate的 calloutAccessoryControlTapped:方法。 You have no need to add target and action for addButton . 您无需为addButton添加目标和操作。 This delegate method gets called if the callout accessory control is tapped(both left and right accessory controls). 如果调出标注附件控件(左右附件控件),则将调用此委托方法。

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

    // Your code here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM