单击注释视图时无法推送新视图



在我的iPhone应用程序中,我有一个带有视图和MKMapView的控制器。
我在地图上显示多个注释,但是当我单击注释视图时,会触发"calloutAccessoryControlTapped",但我无法推送新视图。
自我导航视图为空...最好的方法是什么?我需要在 MKMapView 之上创建一个导航控制器吗?

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
  NSLog(@"annotation clicked"); // => OK
  if ([control isKindOfClass:[UIButton class]]) {
    NSLog(@"annotation clicked 2"); // => OK
    // Get annotation as some stuff needs to be passed to the new view
    MyAnnotation *annotation = (MyAnnotation*)view.annotation;        
    ControlViewController *controlViewController = [[ControlViewController alloc] initWithNibName:@"ControlViewController" bundle:nil];
    controlViewController.thing = annotation.thing;
    NSLog(@"self.navigationController:%@", self.navigationController);  // => null
    // [self.navigationController pushViewController:controlViewController animated:YES];
    [controlViewController release];
  }
}

是的,您的视图控制器需要位于UINavigationController内。查看文档以了解如何操作。

最新更新