0
我有一個模型:事件,我已經將註釋視圖加載到mapview,但是如何從選定的註釋中獲取事件管理對象,以便可以將視圖控制器顯示事件的信息。該viewForAnnotation部分:如何從選定的註釋中獲取管理對象
- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if([annotation class] == MKUserLocation.class) {
//userLocation = annotation;
return nil;
}
REVClusterPin *pin = (REVClusterPin *)annotation;
MKAnnotationView *annView;
annView = [aMapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
if(!annView)
annView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"pin"];
annView.image = [UIImage imageNamed:@"pinpoint.png"];
annView.canShowCallout = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(displayViewController:) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = rightButton;
annView.calloutOffset = CGPointMake(-6.0, 0.0);
}
return annView;
}
和rightCalloutAccessoryView displayViewController部分:
- (void)displayViewController:(id)sender
{
Annotation *annotation = [self.mapView selectedAnnotations][0];
EventsViewController *eventsVC = [[EventsViewController alloc] init];
eventsVC.event = ???
[self.navigationController pushViewController:eventsVC animated:YES];
}
如何從註釋*註釋=管理對象[self.mapView selectedAnnotations] [0]?如果我在Annotation中聲明一個事件,那麼是什麼?
註解類是我自己的。那麼,我應該在Annotation類中聲明一個事件對象?但它墜毀。我還應該做什麼? – 2013-02-17 12:59:15
哦,我明白了。我在REVClusterPin中聲明瞭一個事件屬性,並且它被啓動了。不管怎麼說,還是要謝謝你。我更喜歡選擇器的方式。 – 2013-02-17 13:13:31
您正在使用的選擇器方式似乎有點斷開連接,因爲它依賴於詢問地圖選定的註釋,並假定只選擇了一個,或者第一個數組是您想要的。委託方法實際上爲您提供了被選中的註釋視圖,並從中獲得了正確的註釋。我修改了我的答案以使用您的REVClusterPin類。 – Craig 2013-02-17 18:03:34