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

时间:2012-06-05 11:40:26

标签: ios mkmapview mkannotation mkmapviewdelegate

在我的iphone应用程序中,我有一个带视图的控制器和MKMapView 我在地图上显示了几个注释,但是当我点击注释视图时,会触发“calloutAccessoryControlTapped”,但我无法推送新视图。
self.navigationView为null ...这样做的最佳方法是什么?我是否需要在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];
  }
}

1 个答案:

答案 0 :(得分:0)

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