点击iphone中的特殊注释引脚即可获取索引



这是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;

}

在上面的方法中,我想访问BridgeAnnotation类的myindex。。怎么可能?或者我必须使用其他方法??

有人能帮我吗?

如果你想在点击时捕获注释,那么你应该使用这个委托

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

最新更新