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

时间:2011-06-17 09:32:03

标签: iphone objective-c ios iphone-sdk-3.0

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

1 个答案:

答案 0 :(得分:0)

MKMapViewDelegate的 calloutAccessoryControlTapped:方法就是您所需要的。您无需为 addButton 添加目标和操作。如果轻触标注附件控件(左右附件控件),则会调用此委托方法。

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

    // Your code here
}