ピンをタップするとバルーンが表示され、左右にボタンを配置しています。(添付画像image1)
tagプロパティを使い、どのピンの、どのボタンが押されたかを判別し、添付画像image2のWebViewへと画面を遷移させたいのですが、この場合どの場所へどのように書けば良いのかがいまいち分かりません。
どなたか、アドバイスなどを頂けないでしょうか。
何か参考になるような情報、サイトなどもご存知でしたらぜひお聞かせください。
宜しくお願い致します。m(__)m
下記コードです。
"MapView.h"
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapView : UIViewController<MKMapViewDelegate> {
IBOutlet MKMapView * myMapView;
}
@property(nonatomic, retain) IBOutlet MKMapView *myMapView;
@end
"MapView.m"
#import "MapView.h"
#import "DisplayMap.h"
@implementation MapView
@synthesize myMapView;
- (void)viewDidLoad {
[super viewDidLoad];
myMapView.delegate=self;
NSMutableArray* annotations=[[NSMutableArray alloc] init];
CLLocationCoordinate2D theCoordinate1;
theCoordinate1.latitude = 40.909361;
theCoordinate1.longitude = -74.520264;
CLLocationCoordinate2D theCoordinate2;
theCoordinate2.latitude = 31.244823;
theCoordinate2.longitude = -92.145024;
CLLocationCoordinate2D theCoordinate3;
theCoordinate3.latitude = 36.778261;
theCoordinate3.longitude = -119.417932;
CLLocationCoordinate2D theCoordinate4;
theCoordinate4.latitude = 38.895112;
theCoordinate4.longitude = -77.036366;
CLLocationCoordinate2D theCoordinate5;
theCoordinate5.latitude = 33.468108;
theCoordinate5.longitude = -91.538086;
DisplayMap* myAnnotation1=[[DisplayMap alloc] init];
myAnnotation1.coordinate=theCoordinate1;
myAnnotation1.title=@"New York";
myAnnotation1.subtitle=@"USA";
DisplayMap* myAnnotation2=[[DisplayMap alloc] init];
myAnnotation2.coordinate=theCoordinate2;
myAnnotation2.title=@"Los Angeles";
myAnnotation2.subtitle=@"USA";
DisplayMap* myAnnotation3=[[DisplayMap alloc] init];
myAnnotation3.coordinate=theCoordinate3;
myAnnotation3.title=@"Washington";
myAnnotation3.subtitle=@"USA";
DisplayMap* myAnnotation4=[[DisplayMap alloc] init];
myAnnotation4.coordinate=theCoordinate4;
myAnnotation4.title=@"Las Vegas";
myAnnotation4.subtitle=@"USA";
DisplayMap* myAnnotation5=[[DisplayMap alloc] init];
myAnnotation5.coordinate=theCoordinate5;
myAnnotation5.title=@"Maiami";
myAnnotation5.subtitle=@"USA";
[myMapView addAnnotation:myAnnotation1];
[myMapView addAnnotation:myAnnotation2];
[myMapView addAnnotation:myAnnotation3];
[myMapView addAnnotation:myAnnotation4];
[myMapView addAnnotation:myAnnotation5];
[annotations addObject:myAnnotation1];
[annotations addObject:myAnnotation2];
[annotations addObject:myAnnotation3];
[annotations addObject:myAnnotation4];
[annotations addObject:myAnnotation5];
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
NSLog(@"welcome into the map view annotation");
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorRed;
UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[leftButton addTarget:self
action:@selector(leftClick:)
forControlEvents:UIControlEventTouchUpInside];
pinView.leftCalloutAccessoryView = leftButton;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:@selector(rightClick:)
forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}
- (void)leftClick:(UIButton *)sender {
}
- (void)rightClick:(UIButton *)sender {
}
- (void)dealloc {
[myMapView release];
[super dealloc];
}
"image1"

"image2"



