0
我想在目標c中設置DetailDisclosure
按鈕中的標籤。我的舊代碼是:在詳細信息中設置標籤
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if (annotation == mapView.userLocation)
{
return nil;
}
else
{
static NSString * const identifier = @"MyCustomAnnotation";
static int i;
MKAnnotationView* annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView)
{
annotationView.annotation = annotation;
}
else
{
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:identifier];
}
NSLog(@"%i",annotationView.tag);
annotationView.tag=annotationView.tag+1;
NSLog(@"%i",annotationView.tag);
annotationView.image = [UIImage imageNamed:@"pin1.png"];
annotationView.canShowCallout = YES;
UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"newlocation.png"]];
annotationView.leftCalloutAccessoryView = sfIconView;
UIButton *InformationButton=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[InformationButton addTarget:self action:@selector(annotationButtClicked:) forControlEvents:UIControlEventTouchUpInside];
InformationButton.tag=i;
annotationView.rightCalloutAccessoryView=InformationButton;
UILongPressGestureRecognizer *longGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(LongPressEvent:)];
[annotationView addGestureRecognizer:longGesture];
return annotationView;
}
}
功能實現
- (void)annotationButtClicked:(id)sender
{
NSLog(@"%i",[sender tag]);
}
控制檯輸出爲每次0.1
如何設置標籤的DetailDisclosure
?
你可以修改你的代碼到InformationButton.tag = 10;侮辱InformationButton.tag = i;然後再試一次。我相信我是0,這就是爲什麼你的日誌返回0. – Greg
注意名稱'InformationButton'以小寫字母開頭。 – Larme
請不要使用標籤!有更好的內置方法。見http://stackoverflow.com/questions/9876042/annotation-details-after-detail-disclosure-pressed和http://stackoverflow.com/questions/9462699/how-to-recognize-which-pin-was-tapped 。 – Anna