dizy
dizy

Reputation: 7959

A static SegmentedControl in a NavigationController, loading appropriate ViewControllers

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 ?

Upvotes: 0

Views: 655

Answers (2)

dizy
dizy

Reputation: 7959

I actually figured out a better solution for my problem, so if anyone is interested ...

To create a sub-navigationController in a viewController...

  • Create a UINavigationController in the viewController
  • assign it's delegate to the viewController
  • add the navigationController's view as a subview to the viewController
  • hide the viewController's navigationBar (self.navigationController.navigationBarHidden = YES;)
  • in the viewController implement the following 2 protocols:


-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    [viewController viewWillAppear:animated];
}
-(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
    [viewController viewDidAppear:animated];
}
Bam, you got yourself a UINavigationController inside a UINavigationController>viewController
Hope this helps someone!

Upvotes: 1

Daniel Dickison
Daniel Dickison

Reputation: 21882

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.

Upvotes: 1

Related Questions