我创建了带有图钉的 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;
}