views:

921

answers:

2

Hi, 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!

+3  A: 

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.

Ben Gottlieb
Yep, you do not need a UITableViewController for a table view. It does some stuff that isn't that useful if you're using a table view defined in a nib. Just make sure you declare UIViewController as implementing the table view protocols.
Nimrod
Well, ok. But if I use a UIViewController and implement the <UITableViewDelegate> protocol, will my tableView:cellForRowAtIndexPath: method still be invoked? I'm not using a nib to create the UITableView...Thanks again!
Michael Frost
Just make sure that you set your table's delegate and datasource to point to your viewController, and they'll all be called as normal.
Ben Gottlieb
Thanks alot! Works like a charm =)
Michael Frost
A: 

You may just be able to use presentModalView or whatever. Create a new app with the "Utility" project template and look at how it does this. The modal view stuff won't work though if you don't actually want to switch to a modal view.

Nimrod