Calling popToRootViewControllerAnimated after dismissModalViewControllerAnimated
Asked Answered
G

4

6

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];
Gaither answered 4/10, 2010 at 4:57 Comment(0)
T
6

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.

Terrazas answered 4/10, 2010 at 6:21 Comment(0)
H
2

If you have a navigation controller with a stack of UIViewControllers:

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

Assumes, that view controller in which called modal view controller has navigationController.

Haugen answered 10/8, 2011 at 14:31 Comment(0)
A
1

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?

Afeard answered 19/10, 2011 at 23:35 Comment(0)
D
0

I guess, you are not calling the

[self.navigationController popToRootViewControllerAnimated:YES];

in the target modal viewcontroller. check that.

Druce answered 4/10, 2010 at 6:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.