这是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 。 怎么可能?或者我必须使用其他方法??
任何人都可以帮助我吗?
答案 0 :(得分:3)
如果要在点击上捕获注释,则应使用此委托
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
BridgeAnnotation *annotation = (BridgeAnnotation *)mapView.annotation;
NSInteger *yourIndex = annotation.myindex;
}