在自定义注释上为每个实例创建唯一属性

时间:2015-02-06 01:44:54

标签: ios mapkit mapkitannotation

所以我正在创建一个应用程序,该应用程序使用相同的自定义类进行多个地图注释。每个注释当前都有一个按钮。我想要做的是让每个引脚为主视图控制器类中的变量分配一个唯一值。例如,如果我按下地图上第1针上的按钮,主视图控制器中的某个变量将为1,但如果我按下按钮2,则该变量的值为2等。 这是我的viewController的代码。请注意,viewDidLoad方法中目前有两个自定义引脚注释,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属性?任何帮助都会很棒!

0 个答案:

没有答案