Я создатель noob для iphone developoment, и я пытаюсь определить значение int для аннотации, поэтому я могу взять это значение int и перекрестно ссылаться на массив, чтобы получить соответствующее значение. Однако, когда я пытаюсь получить значение int с помощью .tag-метода, значение всегда возвращается как ноль. Если у меня есть 5 аннотаций, мне нужно определить, какая из них - 0,1,2,3 и 4. Любая помощь очень ценится.Как определить, какая клика MKAnnotation нажата?
МОЙ КОД
- (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;
}