Question: 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 `popToRootViewControllerAnimated`is not working after it.

The code is shown below:

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

```

Answer: 
I ran into something similar to this. You need to make a copy of your self.navigationcontroller first and also retain yourself, so when you call the second pop, there is still a reference to the 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's popped off
[[self retain] autorelease];

    // Pop this controller and replace with another
[navController popViewControllerAnimated:NO];
[navController pushViewController:someViewController animated:NO];

```

see : [How can I pop a view from a UINavigationController and replace it with another in one operation?](https://stackoverflow.com/questions/410471/how-can-i-pop-a-view-from-a-uinavigationcontroller-and-replace-it-with-another-i)
I guess, you are not calling the 

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

```

in the target modal viewcontroller. check that.