Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling popToRootViewControllerAnimated after dismissModalViewControllerAnimated

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];
like image 219
sathish kumar Avatar asked Oct 04 '10 04:10

sathish kumar


2 Answers

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.

like image 128
Jorge Avatar answered Oct 05 '22 15:10

Jorge


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.

like image 41
beryllium Avatar answered Oct 05 '22 16:10

beryllium