Call popToRootViewControllerAnimated after rejecting ModalViewControllerAnimated

I am working on an application in which I call presentModalViewController and after its completion (call dismissModalViewControllerAnimated:YES ) it should immediately call popToRootViewControllerAnimated .

But the dismissModalViewControllerAnimated:YES problem works fine, but popToRootViewControllerAnimated does not work after it.

The code is shown below:

 [self.navigationController dismissModalViewControllerAnimated:YES] ; [self.navigationController popToRootViewControllerAnimated:YES]; 
+6
ios objective-c navigationcontroller
source share
4 answers

Try something like this:

 [self.navigationController dismissModalViewControllerAnimated:YES] ; [self performSelector:@selector(patchSelector) withObject:nil afterDelay:0.3]; -(void)patchSelector{ [self.navigationController popToRootViewControllerAnimated:YES]; } 

This is not so neat, but it should work.

UPDATE: You must use

  [self dismissModalViewControllerAnimated:YES]; 

instead

  [self.navigationController dismissModalViewControllerAnimated:YES] ; 

An object representing a modal is a view controller, not a navigation controller.

+6
source share

If you have a navigation controller with a UIViewControllers stack:

 [self dismissModalViewControllerAnimated:YES]; [(UINavigationController*)self.parentViewController popToRootViewControllerAnimated:YES]; //UIViewController *vc = [[UIViewController new] autorelease]; //[(UINavigationController*)self.parentViewController pushViewController:vc animated:YES]; 

It is assumed that the view controller, which is called the modal view controller, has a navigationController.

+2
source share

I think you are not calling

 [self.navigationController popToRootViewControllerAnimated:YES]; 

in the target modular view manager. Make sure that.

0
source share

I came across something similar. First you need to make a copy of your self.navigationcontroller and also save yourself, so when you call the second pop, there is still a link to NC, and you still exist.

  // locally store the navigation controller since // self.navigationController will be nil once we are popped UINavigationController *navController = self.navigationController; // retain ourselves so that the controller will still exist once it popped off [[self retain] autorelease]; // Pop this controller and replace with another [navController popViewControllerAnimated:NO]; [navController pushViewController:someViewController animated:NO]; 

see How can I open a view from a UINavigationController and replace it with another in one operation?

0
source share

All Articles