Calling popToRootViewControllerAnimated after dismissModalViewControllerAnimated

sathish kumar picture sathish kumar · Oct 4, 2010 · Viewed 12k times · Source

I am working application in which i calling presentModalViewController and once finished(calling dismissModalViewControllerAnimated:YES) it should immediately call popToRootViewControllerAnimated.

But the issue is dismissModalViewControllerAnimated:YES is working properly but popToRootViewControllerAnimatedis not working after it.

The code is shown below:

[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self.navigationController popToRootViewControllerAnimated:YES];

Answer

Jorge picture Jorge · Oct 4, 2010

Try something like this:

[self.navigationController dismissModalViewControllerAnimated:YES] ;
[self performSelector:@selector(patchSelector) withObject:nil afterDelay:0.3];


-(void)patchSelector{
  [self.navigationController popToRootViewControllerAnimated:YES]; 
}

It is not so neat but it should work.

UPDATE: You should use

 [self dismissModalViewControllerAnimated:YES];

instead

 [self.navigationController dismissModalViewControllerAnimated:YES] ;

The object that is presenting the modal is the view controller, not the navigation controller.