Objective-c – Adding UITableViewControllers tableview to new UIView

iphoneobjective cuitableview

I have a simple question.

I have a normal UITableViewController displaying a UITableView. When the user taps a button in the top right corner of my application I want the TableView to flip from right to left and then display a new UIView. I've found the animation UIViewAnimationTransitionFlipFromRight which flips the current view and replaces it with a new one. However, the animation involves removing the current view from its superview and then adding the new view to the same superview.
The problem is that when I am trying to do this in my UITableViewController class i only have one view – the UITableView – which I need to remove. When the UITableView has been removed I have no view left to add my new view to, and the screen goes blank.

My idea of getting around this problem is to create a UIView and put the UITableView in that view. I would the in the animation remove the UITableView from the UIView and then add my new view to the same UIView.
Something like this when initializing:

superViewTest = [[UIView alloc] initWithFrame:self.tableView.frame];
[superViewTest addSubview:self.tableView];

And then like this when animating the flip:

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
[self.tableView removeFromSuperview];
[superViewTest addSubview:self.mapView];

Or does the UITableView in the UITableViewController already have a superview I'm not aware of?

I wish I could have explained this better, thanks in advance!

Best Answer

I would suggest you use a standard UIViewController instead of a UITableViewController. Then you can control, directly, both the table and its parent view. Add the table as a subview of the UIViewController's view, and swap it with your flipside view the way you described.