2012-03-28 52 views
0

這是BridgeAnnotation接口,它具有MKAnnotation如何獲得指數particlular註釋針的點擊在iphone

的代表
@interface BridgeAnnotation : NSObject <MKAnnotation> 
{ 

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

我在我的方法類似如下

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]; 
設定以 myindex變量

這是我overiding方法

- (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; 


} 

在上述方法中,我想訪問BridgeAnnotation類的myindex .. 這怎麼可能?或者我必須使用其他方法呢?

任何人都可以幫助我嗎?

+0

哎你是如何設定'大橋Annotation' – 2013-06-24 06:04:05

回答

3

如果你想捕捉點擊註釋,那麼你應該使用這個委託

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 
{ 
    BridgeAnnotation *annotation = (BridgeAnnotation *)mapView.annotation; 
    NSInteger *yourIndex = annotation.myindex; 
} 
+0

感謝其給予正確的索引的索引。 – IOSDev 2015-04-20 11:37:13