2009-09-16 64 views
10

我最近遇到了this website,我一直試圖添加到我的電話中查看按鈕(從圖像)。將附件視圖按鈕添加到MKMapView調用註釋?

網站示例上的代碼工作得很好,但是當我試圖將相同的代碼添加到我的項目中時,我得不到相同的結果。

顯然有一些我錯過了,但我似乎無法工作這一個!

這裏是我的代碼爲註解:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{ 
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"]; 
    annView.pinColor = MKPinAnnotationColorGreen; 

    UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    advertButton.frame = CGRectMake(0, 0, 23, 23); 
    advertButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
    advertButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; 

    [advertButton setImage:[UIImage imageNamed:@"button_right.png"] forState:UIControlStateNormal]; 
    [advertButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside]; 

    annView.rightCalloutAccessoryView = advertButton; 

    annView.animatesDrop=TRUE; 
    annView.canShowCallout = YES; 
    annView.calloutOffset = CGPointMake(-5, 5); 
    return annView; 
} 

任何幫助,將不勝感激! :)

+0

不幸的是,你提供的鏈接是死的 – 2016-10-14 20:59:09

回答

4

對不起回答我自己的問題,但這是通過將MKMapView的委託設置到ViewController解決。 Phew,花了我一段時間來弄清楚這一點,它非常簡單!

15

那傢伙正在使用自定義圖像來模仿詳細信息披露。實際上,你可以得到標準詳細披露很容易:

[UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
+0

啊謝謝,總是有用的做事情他們是如何意味着要做:) – 2009-10-19 11:38:47

11

而不是設置的目標是你一個人在這裏:

[advertButton addTarget:self action:@selector(showLinks:) forControlEvents:UIControlEventTouchUpInside]; 

你可以使用默認的委託:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control