views:

437

answers:

2

I have 2 separate TableViewControllers. At one particular instance I would like to be able to load a ViewController which will place a SegmentedControl in the NavigationController...which in turn will load the appropriate TableViewController.

Currently I have the SegmentedControl just pushishing the correct TableViewController and it works fine if I manually initiate the push. However if I try to do the push anytime before ViewDidAppear, the pushed TableViewController wont display anything..it will trace things ok though.

And just to note, the 2 TableViewConrollers are both different enough that I can't just use one Controller and just switch the dataSource.

Any suggestions ?

+1  A: 

Instead of pushing the table view controllers to the nav controller, you probably want to have a view controller that contains the two table controllers. Then, add one of the table views as a subview of the view controller's view. I.e. when the segmented controller is switched, you do something like:

[self.tableController1.view removeFromSuperview];
[self.view addSubview self.tableConttroller2.view];

You'll probably also have to send the appropriate view[Will/Did][Appear/Disappear] messages to your table controllers to make sure they're initialized properly.

Daniel Dickison
I just relized that this doesn't work for me, because my tableViewControllers are drill down as well, and thus need the navigationController. Any other ideas ?
dizy
The table controllers can have a reference to the top-level nav controller and simply push sub views onto that. However, if you do it this way the segmented control won't be visible when you drill down, which may or may not be what you want.
Daniel Dickison
+1  A: 
dizy