2015-05-03 100 views
0

我正在嘗試將附件按鈕添加到我的貼圖註釋中,但無法使其正常工作。我已經搜索了很多,但似乎沒有任何工作。請幫幫我!註釋標註上的附件按鈕

這裏是我的代碼:

//Annotations 

//Pildammsparken 
CLLocationCoordinate2D pildLocation; 
pildLocation.latitude = PILD_LATITUDE; 
pildLocation.longitude = PILD_LONGITUDE; 
//Malmöhus Slott 
CLLocationCoordinate2D malmohusLocation; 
malmohusLocation.latitude = MALMOHUS_LATITUDE; 
malmohusLocation.longitude = MALMOHUS_LONGITUDE; 

//Pildammsparken - Annotation 
MapPin *annPild = [[MapPin alloc] init]; 
annPild.title = @"Title"; 
annPild.subtitle = @"Subtitle"; 
annPild.coordinate = pildLocation; 
[mapview addAnnotation:annPild]; 
//Malmöhus slott - Annotation 
MapPin *annMalmohus = [[MapPin alloc] init]; 
annMalmohus.title = @"Title"; 
annMalmohus.subtitle = @"Subtitle"; 
annMalmohus.coordinate = malmohusLocation; 
[mapview addAnnotation:annMalmohus]; 

[mapview setShowsPointsOfInterest:NO]; 

我希望有一個按鈕的小注釋,將帶你到一個頁面,您可以閱讀更多的終結。

回答

1

設置你的ViewController是地圖視圖的委託並實現以下方法:

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

    MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"PinAnnotationView"]; 
    if (!annotationView) { 
     annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"PinAnnotationView"]; 
     annotationView.canShowCallout = YES; 
     annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    } else { 
     annotationView.annotation = annotation; 
    } 

    return annotationView; 
} 

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control { 
    MKPointAnnotation *annotation = view.annotation; 
    NSLog(@"user tapped annotation with title: %@", annotation.title); 
}