КАК получить индекс по клику конкретного пин-кода аннотации в iphone - PullRequest
0 голосов
/ 28 марта 2012

Это интерфейс BridgeAnnotation с делегатом MKAnnotation

@interface BridgeAnnotation : NSObject <MKAnnotation>
{

}
@property(nonatomic,retain) NSString *lat,*lon,*titlevalue,*subtitlevalue;
@property(nonatomic,assign) NSInteger  myindex;
@end

Я устанавливаю значение переменной myindex в моем методе, как показано ниже

  BridgeAnnotation *bridgeAnnotation = [[BridgeAnnotation alloc] init];
   [bridgeAnnotation setLat:[@"" stringByAppendingFormat:@"%f",theCoordinate.latitude]];
   [bridgeAnnotation setLon:[@"" stringByAppendingFormat:@"%f",theCoordinate.longitude]];
   [bridgeAnnotation setTitlevalue:[PMLObj ProductTitle]];
   [bridgeAnnotation setSubtitlevalue:[[PMLObj ProductPrice] stringByAppendingFormat:@"$"]];
    [bridgeAnnotation setMyindex:i];

   [self.mapView addAnnotation:bridgeAnnotation];

Это мой метод перебора

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;


        static NSString* BridgeAnnotationIdentifier = @"bridgeAnnotationIdentifier";
        MKPinAnnotationView* pinView = (MKPinAnnotationView *)
        [mapView dequeueReusableAnnotationViewWithIdentifier:BridgeAnnotationIdentifier];
        if (!pinView)
        {
            UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


            NSLog(@"---%d",rightButton.tag);
            [rightButton addTarget:self
                            action:@selector(showDetails:)
                  forControlEvents:UIControlEventTouchUpInside];
            customPinView.rightCalloutAccessoryView = rightButton;

            return customPinView;
        }
        else
        {
            pinView.annotation = annotation;
        }
        return pinView;


}

В приведенном выше методе я хочу получить доступ к myindex класса BridgeAnnotation .. Как это возможно? ИЛИ Я должен использовать другой метод для этого ??

Кто-нибудь может мне помочь?

1 Ответ

3 голосов
/ 28 марта 2012

Если вы хотите захватить аннотацию по клику, вам следует использовать этот делегат

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
  BridgeAnnotation *annotation = (BridgeAnnotation *)mapView.annotation;
  NSInteger *yourIndex = annotation.myindex;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...