Calling popToRootViewControllerAnimated after dismissModalViewControllerAnimated

前端 未结 4 1442
孤独总比滥情好
孤独总比滥情好 2021-01-05 14:04

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

相关标签:
4条回答
  • 2021-01-05 14:39

    I guess, you are not calling the

    [self.navigationController popToRootViewControllerAnimated:YES];
    

    in the target modal viewcontroller. check that.

    0 讨论(0)
  • 2021-01-05 14:42

    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?

    0 讨论(0)
  • 2021-01-05 14:53

    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.

    0 讨论(0)
  • 2021-01-05 15:01

    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.

    0 讨论(0)
提交回复
热议问题