我是一个菜鸟到iPhone发展问题浅析和我试图确定注解的int值,所以我可以再采取int值和交叉引用它到一个数组中获得相应的值。 然而,当我尝试用.TAG方法获取int值的值总是返回为零。 如果我有5个annontations我需要能够确定哪些annontation是0,1,2,3和4。任何帮助是极大的赞赏。
我的代码
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
if (view.selected==YES) {
NSInteger annotationIndex = view.tag; //Always returns zero
NSLog(@"annotationIndex: %i", annotationIndex);
}
}
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
// Define your reuse identifier.
static NSString *identifier = @"MapPoint";
if ([annotation isKindOfClass:[MapPoint class]]) {
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
} else {
annotationView.annotation = annotation;
}
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.animatesDrop = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSInteger clickIndex = rightButton.tag; //Always returns zero, despite there being 5 annotations
NSLog(@"buttonIndex: %i", clickIndex);
[rightButton addTarget:self
action:@selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = rightButton;
return annotationView;
}
return nil;
}