2013-03-25 92 views
1

我创建了MKMapView,其上有一个针。显示问题的MKAnnotation

当我按下某个引脚时,我看到了标题和副标题,但我希望不点击即可看到它。 因此,我希望标题和副标题在地图显示后立即出现。

这里是我的代码:

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; 

} 
+0

您是否尝试过在viewdidload方法中调用viewForAnnotation?引脚出现后? – Lucabro 2013-03-25 12:43:44

+1

Patel正确回答 – 2013-03-25 12:48:33

回答