2
我想單擊註解的詳細按鈕時執行詳細視圖。但是每個引腳必須具有不同的細節視圖。要做到這一點,我嘗試設置標籤按鈕。然後我會在calloutAccessoryControlTapped方法中使用這個標籤來添加它們的詳細視圖。我的代碼如下。但它停在for循環。我該如何解決這個問題?如何獲取UIButtonTypeDetailDisclosure在目標c中單擊的註釋?
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
static NSString *annReuseId = @"test";
MKPinAnnotationView *annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:annReuseId];
if (annView == nil)
{
annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annReuseId];
annView.animatesDrop = YES;
annView.canShowCallout = YES;
[annView setSelected:YES];
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView=detailButton;
for (int i=0; i<=[[mapView annotations] count]; i++)
{
detailButton.tag =[[[mapView annotations] objectAtIndex: i] integerValue];
NSLog(@"button %i",detailButton.tag);
}
}
else {
annView.annotation = annotation;
}
return annView;
}
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"calloutAccessoryControlTapped: annotation = %@", view.annotation);
RestaurantsView *detailView=[[RestaurantsView alloc] initWithNibName:@"RestaurantsView" bundle:nil];
//here, can set annotation info in some property of detailView
// [[self navigationController] pushViewController:detailView animated:YES];
// [detailView release];
[self.view addSubview:detailView.view];
}
nslog消息是calloutAccessoryControlTapped:annotation =什麼是是什麼意思? –
2012-02-09 07:37:33
我怎麼知道點擊了哪個按鈕? – 2012-02-09 07:40:13
'MKUserLocation'是系統爲用戶位置提供的註釋(藍點)。我不知道你是否有意或無意,但是你的'viewForAnnotation:'把這個藍點變成紅色的針。我建議你閱讀[文檔](https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html)以及參考[Apple的示例代碼] (https://developer.apple.com/library/ios/#samplecode/MapCallouts/Listings/MapViewController_m.html) – 2012-02-09 08:10:35