2009-12-06 30 views
5

Tôi muốn thêm chú thích vào một nút MapView có tiết lộ trên đó và tôi không thể tìm ra chú thích đó.Thêm chú thích có thể nhấp vào UIMapView

Tôi đã tạo ra một lớp dấu vị trí phù hợp với các giao thức MKAnnotation và sau đó tạo ra các MapView và thêm dấu vị trí:

// Add annotation information 
PlaceMark *venuePlacemark = [[PlaceMark alloc] initWithCoordinate:location]; 
venuePlacemark.locationTitle = [locationDictionary valueForKey:VENUE_NAME_KEY]; 
venuePlacemark.locationSubtitle = @"Touch to show in Google Maps"; 

// Create the accessory button on the placemark 
[venueMap addAnnotation:venuePlacemark]; 
[venueMap setRegion:region animated:TRUE]; 
[venueMap regionThatFits:region]; 

này tất cả các công trình và một pin được hiển thị mà khi chạm vào màn hình cuộc gọi đúng ra văn bản . Tôi không thể tìm ra cách thêm nút tiết lộ vào cuộc gọi. Xin lỗi nếu đây là tiểu học và bất kỳ trợ giúp sẽ được đánh giá cao.

Dave

+0

Đó là một câu hỏi hay. Các tài liệu về điều này là loại khủng khiếp. Apple thực sự giả định rất nhiều kiến ​​thức kỳ cựu về SDK của họ khi họ viết những tài liệu này. –

Trả lời

9

suy nghĩ tôi đã figured it out ... Thực hiện phương pháp đại biểu sau đây:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    MKPinAnnotationView *dropPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"venues"]; 

    UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    [disclosureButton addTarget:self action:@selector(mapCallOutPressed:) forControlEvents:UIControlEventTouchUpInside]; 

    dropPin.rightCalloutAccessoryView = disclosureButton; 
    dropPin.animatesDrop = YES; 
    dropPin.canShowCallout = YES; 

    return dropPin; 
} 
+2

Điều này làm việc nhưng thay vì [disclosureButotn addTarget] bạn có lẽ nên sử dụng phương thức đại biểu được xác định trước - (void) mapView: (MKMapView *) chú thích mapViewXem: (MKAnnotationView *) xem calloutAccessoryControlTapped: (UIControl *) control –

+0

Cảm ơn Jasconius ... sẽ cung cấp cho nó một whirl ... –

Các vấn đề liên quan