2012-07-27 25 views
0

我使用此代碼來創建我的自定義註釋視圖。MKAnnotationView

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation { 

    MKPinAnnotationView *pinAnnotation = nil; 
    if(annotation != myMapView.userLocation) { 
     static NSString *defaultPinID = @"myPin"; 
     pinAnnotation = (MKPinAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; 
     if (pinAnnotation == nil) 

      pinAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID]; 

     pinAnnotation.canShowCallout = YES; 

     //instatiate a detail-disclosure button and set it to appear on right side of annotation 
     UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     [infoButton addTarget:self 
         action:@selector(showRestaurantDescription) 
      forControlEvents:UIControlEventTouchUpInside]; 
     pinAnnotation.rightCalloutAccessoryView = infoButton; 
    }  
    return pinAnnotation; 
} 

我的問題是如何發送參數到我的選擇:-showRestaurantDescription:

當我想到我可以添加標籤按鈕,處理它,但我需要選擇最好的方法,因爲我有與我的餐廳陣列,當我點擊具體的針我需要顯示當前的餐廳。所以在這種情況下,標籤不是很方便,因爲我認爲。

回答

2

您應該使用委託方法mapView:annotationView:calloutAccessoryControlTapped:來偵聽按鈕上的按鈕。該方法通過了一個annotationView,其中有一個annotation屬性。您可以使用註釋屬性來確定它是哪家餐館。

此外,您是否忘記了冒號action:@selector(showRestaurantDescription)