Search code examples
iphoneiosthree20popviewcontrolleranimated

How to get a return value from a ViewController? // popViewControllerAnimated twice? Double back?


I have included the Three20 Library and use the TTNavigator for my views.

My goal is to flip from view 4 back to view 2.

The only solution I found for this, is to call popViewControllerAnimated in View 4 to get to View 3, then in the ViewDidAppear in view 3 call the popViewControllerAnimated again, to get to View 2.

Problem is, of course, I only want to call the popViewControllerAnimated in View 3 ViewDidAppear only, when the ViewDidAppear is called from View 4 to View 3, not in other cases (e.g. View 2 opens View 3).

So as far as I see I have to set a BOOL property or something like this, but how? I can't work with delegates here, because of the URL-Navigation given by Three20.


Solution

  • Use UINavigationController's -popToViewController:animated: method:

    // This is a method of your UIViewController subclass with view 4
    - (void) popTwoViewControllersAnimated:(BOOL)animated {
        NSInteger indexOfCurrentViewController = [self.navigationController.viewControllers indexOfObject:self];
        if (indexOfCurrentViewController >= 2)
            [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:indexOfCurrentViewController - 2] animated:animated];
    }