I am trying to push a view when a user clicks on an annotation, I have the following code in place:
- (void) mapView: (MKMapView *) mapView annotationView:(MKAnnotationView *) view calloutAccessoryControlTapped:(UIControl *) control
{
childController = [[NeighborProfileViewController alloc] initWithNibName:@"NeighborProfileViewControlle开发者_StackOverflowr" bundle:nil];
childController.title = view.annotation.title;
childController.uid = [((NeighborMapAnnotation *)(view.annotation)) uid];
[self.navigationController pushViewController:childController animated:YES];
}
I know that the code executes inside this fragment as I tried to print out something and it did print. However, why isn't it changing views to the view that I already push?
Is this because this view is actually a subView of the main view, which actually has the navigation controller? If this is the case, then how do I get around this. Here's the code that loads the subView:
-(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];
}
in other words the calloutAccessoryControlTapped is inside the mapViewController
Your code is insufficient to answer the following questions:
Is your navigation controller initialized?
Even though you are calling self.navigationController
, if it is nil
, then nothing will happen.
Is the xib name spelled correctly? If you push a controller onto the navigation stack with an incorrect xib name, an error may not be thrown and your controller will not be pushed onto the stack.
EDIT:
You need to create an instance of a UINavigationController before you show your initial view. Here is an example of presenting a modal view:
YourViewController* rootViewController; /* however you are creating the initial view */;
UINavigationController navController =
[[UINavigationController alloc] initWithRootViewController:rootViewController];
[rootViewController release];
[self presentModalViewController:navController animated:YES];
[navController release];
your mapviewcontroller doesn't have a reference to the navigationcontroller. your main view controller does. so what you need to do is pass the reference to your navigation controller onto the maview controller, and push the view onto that. Let me know if you have any questions
精彩评论