views:

643

answers:

2

I'm having some trouble getting a view to flip. I have the following code in my View Controller:

- (void)loadFlipsideViewController {
    ProblemViewFlipController *viewController = [[ProblemViewFlipController alloc] initWithNibName:@"ProblemViewFlip" bundle:nil];
    self.problemViewFlipController = viewController;
    [viewController release];
}


- (void) flipView {

    if (problemViewFlipController == nil) {
        [self loadFlipsideViewController];
    }

    UIView *mainView = self.view;
    UIView *flipView = problemViewFlipController.view;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];

    [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:self.view cache:YES];

    if ([flipView superview])
    {
     [flipView removeFromSuperview];
     [self.view addSubview:mainView];
    }
    else
    {
     [mainView removeFromSuperview];
     [self.view addSubview:flipView];
    }

    [UIView commitAnimations];
}

The problem is, is that when I call flipView, the view is replaced with a blank view (i.e. nothing in the view I'm flipping to is displayed).

Is there something obvious I'm missing here? (I suspect there is!)

+2  A: 

Not positive, but I think you need to use a 'controller' to flip the views. Looks like you're using one of the flipped views as the controller. Just add a root controller to flip your views.

Code like this should work from the root controller:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; // self.view is the root controller's view
[mainViewController viewWillAppear:YES];
[flipViewController viewWillDisappear:YES];
[flipViewController.view removeFromSuperview];
[self.view  addSubview:mainViewController.view];
[flipViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
[UIView commitAnimations];
Sophtware
This put me on the right track - I was flipping between the view on the current controller and another rather than using this controller to flip between the views on two other controllers. Cheers!
Mr. Matt
A: 

Based on the variable names, it looks like this is adapted from the default "Utility" application template you get from XCode. If the template project works, and yours doesn't, then you've obviously changed something you shouldn't have :-)

Chances are, one of the outlets in your controller that should be pointing at a view, isn't. Double-check your Nibs, and check the values of the outlets in the debugger. If all else fails, start over again from the template, and see at what point it stops working.

Mark Bessey