我在注释标注中添加了一个按钮。在按钮的单击事件上,我想推送另一个视图控制器,其中包含标题和副标题等注释的详细信息。但问题是我无法获得这些细节。
这是我到目前为止所做的:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)userannotation
{
if ([annotation isMemberOfClass:[MKUserLocation class]])
{
return nil;
}
MKPinAnnotationView *v =[[MKPinAnnotationView alloc] initWithAnnotation:userannotation reuseIdentifier:@"ku"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
button.frame = CGRectMake(0, 0, 24, 24);
// [button addTarget:self action:@selector(callOutPressed:) forControlEvents:UIControlEventTouchUpInside];
v.rightCalloutAccessoryView = button;
v.canShowCallout = YES;
return v;
}
/*
- (void) callOutPressed:(id)sender
{
[ dict setValue:annotation.subtitle forKey:@"jid"] ;
[dict setValue:annotation.title forKey:@"name"];
NSLog(@"annotation values - %@",dict); // this shows null
*/
好。我试过用这个:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
NSLog(@"display name :-%@", view.annotation.title);// shows name
[dict setValue:view.annotation.title forKey:@"name"];//dict shows 0 key/value pairs and the app crashes.
NSLog(@"output :-%@", dict); //shows null
}
这样做的正确方法是什么?