ピンを付けてMKMapViewを作成しました。
ピンを押すとタイトルとサブタイトルが見えますが、タップせずに見たいです。なので、地図を表示した直後にタイトルとサブタイトルを表示したいです。
これが私のコードです:
self.mapView = [[[MKMapView alloc]init] autorelease];
mapView.frame = self.view.bounds;
mapView.delegate = self;
[self.view addSubview:mapView];
location = CLLocationCoordinate2DMake(lattitude, longitude);
MKCoordinateRegion region = self.mapView.region;
region.center = location;
region.span.longitudeDelta = kSpan;
region.span.latitudeDelta = kSpan;
[self.mapView setRegion:region animated:YES];
CustomMapAnnotation *newAnnotation = [[CustomMapAnnotation alloc] init];
newAnnotation.title = @"Title";
newAnnotation.subtitle = @"Subtitle";
newAnnotation.accessibilityTraits = UIAccessibilityTraitButton;
newAnnotation.coordinate = location;
annotation = newAnnotation;
[mapView addAnnotation:annotation];
[newAnnotation release];
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotationDel
{
MKPinAnnotationView *pinView = nil;
static NSString *defaultPinID = @"mapPin";
pinView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil)
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotationDel reuseIdentifier:defaultPinID] autorelease];
pinView.pinColor = MKPinAnnotationColorRed;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
[pinView setSelected:YES];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(detailButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}