0

所以我正在制作一个应用程序,该应用程序具有使用相同自定义类制作多个地图注释的应用程序。每个注释当前都有一个按钮。我想要做的是让每个引脚为主视图控制器类中的变量分配一个唯一值。例如,如果我按下地图上引脚 1 上的按钮,则主视图控制器中的某个变量的值为 1,但如果我按下按钮 2,则该变量的值为 2,依此类推。这是代码对于我的视图控制器。请注意,viewDidLoad 方法中当前有 2 个自定义引脚的注解,即 GrandCarousel 和 OrientExpress。

- (void)viewDidLoad {
[super viewDidLoad];
self.mapView.delegate = self;
self.mapView.mapType = MKMapTypeSatellite;

CLLocationCoordinate2D startCoord = CLLocationCoordinate2DMake(34.422409, -118.596120);
MKCoordinateRegion adjustedRegion = [self.mapView regionThatFits:MKCoordinateRegionMakeWithDistance(startCoord, 1000, 1000)];
[self.mapView setRegion:adjustedRegion animated:YES];

CLLocationCoordinate2D pinLocationGrandCarousel = CLLocationCoordinate2DMake(34.422413, -118.596112);
WOMapAnnotation *GrandCarousel = [[WOMapAnnotation alloc] initWithCoordinate:pinLocationGrandCarousel title:@"Grand Carousel" andSubTitle:nil];
GrandCarousel.selectedSection = 0;
GrandCarousel.selectedRow = 0;
[_mapView addAnnotation:GrandCarousel];

CLLocationCoordinate2D pinLocationOrientExpress = CLLocationCoordinate2DMake(34.422578, -118.596362);
WOMapAnnotation *OrientExpress = [[WOMapAnnotation alloc] initWithCoordinate:pinLocationOrientExpress title:@"Orient Express" andSubTitle:nil];
GrandCarousel.selectedSection = 0;
GrandCarousel.selectedRow = 1;
[_mapView addAnnotation:OrientExpress];
}


- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>) annotation
{
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinLocation"];

newAnnotation.canShowCallout = YES;
newAnnotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

return newAnnotation;
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control{
NSLog(@"you touched the disclosure indicator for ride");
}

因此,如果您注意到,WOMapAnnotation 类的每个实例都具有自定义属性 selectedSection 和 selectedRow 以及正常的标题和坐标。该按钮的显示与我希望的完全一样,但该按钮的作用完全相同。所以我的总体问题是如何根据所点击的注释访问 viewController 类中的 selectedRow 和 selectedSection 属性?任何帮助都会很棒!

4

0 回答 0