2011-02-02 91 views
1

我想,当用户点击一个注解推看法,我在的地方下面的代码:上的注释时,点击推视图

- (void) mapView: (MKMapView *) mapView annotationView:(MKAnnotationView *) view calloutAccessoryControlTapped:(UIControl *) control 
{ 
    childController = [[NeighborProfileViewController alloc] initWithNibName:@"NeighborProfileViewController" bundle:nil]; 
    childController.title = view.annotation.title; 
    childController.uid = [((NeighborMapAnnotation *)(view.annotation)) uid]; 
    [self.navigationController pushViewController:childController animated:YES]; 
} 

我知道这个代码片段内执行因为我试图打印出一些东西,而且确实打印出来了。然而,为什么它不改变我已经推动的观点?

这是因为这个视图实际上是主视图的子视图,它实际上有导航控制器?如果是这种情况,那我该如何解决这个问题。下面是加载子视图代码:

-(IBAction) toggleAction:(id) sender { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; 

    if(self.navigationItem.rightBarButtonItem.title == @"List"){ 
     self.navigationItem.rightBarButtonItem.title = @"Map"; 
     [mapViewController.view removeFromSuperview]; 
    }else { 
     [self.view addSubview:mapViewController.view]; 
     [self.view sendSubviewToBack:self.view]; 
     self.navigationItem.rightBarButtonItem.title = @"List"; 
    } 

    [UIView commitAnimations]; 

} 

换句话说calloutAccessoryControlTapped是的MapViewController

回答

0

你的代码中是不足以回答以下问题:

是您的导航控制器初始化? 即使你打电话self.navigationController,如果它是nil,那么什么都不会发生。

xib名拼写是否正确?如果您将控制器压入导航堆栈并显示错误的xib名称,则可能不会抛出错误,并且您的控制器不会被推入堆栈。

编辑:

你需要你显示你的初始视图之前创建一个UINavigationController的一个实例。以下是展示模式视图的示例:

YourViewController* rootViewController; /* however you are creating the initial view */; 

UINavigationController navController = 
     [[UINavigationController alloc] initWithRootViewController:rootViewController]; 

[rootViewController release]; 

[self presentModalViewController:navController animated:YES]; 
[navController release]; 
+0

xib是正确的,代码是一样的确切的事情,我用来推一个控制器时,用户在表视图 – aherlambang 2011-02-02 04:24:44

0

您的mapviewcontroller没有对导航控制器的引用。你的主视图控制器。所以你需要做的就是将你的导航控制器的引用传递到maview控制器上,并将视图推送到该控制器上。让我知道如果您有任何问题