Search code examples
objective-ciosuinavigationcontrollerpoptoviewcontroller

popToRootViewController forward animation


In my library I have a loading view which pops to a input view. When the user is done with the input view it should go back to the loading view to do some magic again and when done it should show up a third view.

Now, from a usability view I don't want to "slide back" to the loading view, neither do I want to allocate a new loading view when I already have one in memory.

Is there some way I can popToRootViewController while sliding the view forwards? (Yes, I remove the back button in the loading view)..


Solution

  • Alright here goes - perhaps try using something like this

    // This goes in whatever view controller you want to pop with
    - (void)popToRootWithForwardAnimation
    {
        NSMutableArray * viewControllers = [[[self.navigationController viewControllers] mutableCopy] autorelease]
        UIViewController * rootViewController = [viewControllers objectAtIndex:0]
        [viewControllers removeObjectAtIndex:0]; // try using with and without this line?
        [viewControllers addObject:rootViewController];
    
        [self.navigationController setViewControllers:viewControllers animated:YES];
    }
    
    // This goes in the root view controller
    - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated]
        NSMutableArray * viewControllers = [[[self.navigationController viewControllers] mutableCopy] autorelease]
        if ([viewControllers count] > 1)
        {
            [viewControllers removeAllObjects];
            [viewControllers addObject:self];
    
            [self.navigationController setViewControllers:viewControllers animated:NO];
        }
    
        … 
        …
    }