簡體   English   中英

在iPhone SDK中,如何在單擊MKMapView的注釋釘時切換到另一個視圖?

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

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的 calloutAccessoryControlTapped:方法。 您無需為addButton添加目標和操作。 如果調出標注附件控件(左右附件控件),則將調用此委托方法。

- (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