0

我想在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];

此代码应该已将详细视图推到顶部并显示详细视图,但它不喜欢,

任何帮助将不胜感激,我想做的是当有人点击地图视图上注释的右侧按钮时,我想显示详细视图,提前谢谢你..

4

2 回答 2

1

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

于 2012-03-08T06:36:43.800 回答
0

谢谢您的帮助,我可以通过更改 showDetails 方法打开 detailViewController

- (void)showDetails:(id)sender
    {
      detailViewController *dvController = [[detailViewController alloc] initWithNibName:nil bundle:nil];
      [self presentModalViewController:dvController animated:YES];
      [dvController release];
      dvController = nil;
    }
于 2012-03-13T17:18:41.727 回答