尝试在xcode中的mapview注释上点击右键时推送详细视图

时间:2012-03-07 22:46:12

标签: xcode mkmapview pushviewcontroller mkannotationview mkpinannotationview

我想在xcode中点击mapview注释上的右键后显示详细视图,但我无法显示视图,  我的代码:

- (void)showDetails:(id)sender
{
  [self.navigationController setToolbarHidden:YES animated:NO];

[self.navigationController pushViewController:self.detailViewController animated:YES];

}



- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString* BridgeAnnotationIdentifier = @"bridgeAnnotationIdentifier";

MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                       initWithAnnotation:annotation reuseIdentifier:BridgeAnnotationIdentifier] autorelease];
customPinView.pinColor = MKPinAnnotationColorPurple;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;

UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
NSLog(@"%@",rightButton);
[rightButton addTarget:self
                action:@selector(showDetails:)
      forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
return customPinView;//[kml viewForAnnotation:annotation];
}

调用showDetails方法但不能将detailViewController推送到顶部,

[self.navigationController pushViewController:self.detailViewController animated:YES];

此代码应将详细信息视图推送到顶部并显示detailView但不满意,

任何帮助都会非常感激,我想做的是当有人在mapview上点击注释的右键时,我想要显示一个详细视图,提前感谢你..

2 个答案:

答案 0 :(得分:1)

不需要目标/操作,在点击标注附件视图时会调用一个委托方法:mapView:annotationView:calloutAccessoryControlTapped:

答案 1 :(得分:0)

谢谢你的帮助,我可以通过改变我的showDetails方法来打开detailViewController

- (void)showDetails:(id)sender
    {
      detailViewController *dvController = [[detailViewController alloc] initWithNibName:nil bundle:nil];
      [self presentModalViewController:dvController animated:YES];
      [dvController release];
      dvController = nil;
    }