2011-04-28 26 views

回答

3

mapView:viewForAnnotation:委託方法,將canShowCallout屬性設置爲NO並使用mapView:didSelectAnnotationView:來檢測觸摸:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 

    static NSString *annotIdentifier = @"annot"; 
    MKPinAnnotationView *pav = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annotIdentifier]; 
    if (!pav) 
    { 
     pav = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotIdentifier] autorelease]; 
     pav.canShowCallout = NO; 
    } 
    else 
    { 
     pav.annotation = annotation; 
    } 

    return pav; 
} 

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 
{ 
    NSLog(@"annotation touched: %@", view.annotation.title); 
} 

確保地圖視圖的委託屬性的設置,否則這些方法將不會被調用。

相關問題