Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add navigationcontroller to detail view in splitview

I am following this example: http://doronkatz.com/ipad-programming-tutorial-hello-world. This example works great.

Now i want 3 tabs in the splitview and for each tab a new navigationcontroller. But i don't know how to implement it. I go to this code:

- (void)setDetailItem:(id)newDetailItem {
if (detailItem != newDetailItem) {
    [detailItem release];
    detailItem = [newDetailItem retain];

    // Update the view.
    navigationBar.topItem.title = detailItem;

    if ([detailItem isEqualToString:@"Test"]) {
        TestViewController *testViewController = [[TestViewController alloc] initWithNibName:@"TestView" bundle:nil];
        [self.navigationController pushViewController:testViewController animated:NO];
        [mapViewController release];

    }
    if ([detailItem isEqualToString:@"Test2"]) {

    }

}

if (popoverController != nil) {
    [popoverController dismissPopoverAnimated:YES];
}        

But i know that i actually don't have to use 'pushviewcontroller', i just want a new navigationcontroller starting from that point, and so for each tab in the splitview. How can i accomplish this? I know it's really basic, but i cant figure it out.

Thanks.

like image 378
meersmans Avatar asked Sep 23 '10 07:09

meersmans


1 Answers

As I understand your requirement, you want a split view controller as the main controller. The left panel will select an item and the right detail view for that item will contain 3 tabs. Each tab will have a navigation controller. The app store follows a pattern similar to the detail view.

Its important to structure your controllers as a tree.

  • root: split view controller
    • list view: table controller (MasterViewController for selecting fruit)
    • detail view: tab controller (all info about watermelon)
      • tab1: navigation controller
        • page 1: first tab root controller (history of watermelons)
      • tab2: navigation controller
        • page 1: first tab root controller (map of watermelon farms)
      • tab3: navigation controller
        • page3: first tab root controller (watermelon recipes)

With this pattern you can create the controller structure on viewDidLoad, but then change the contents of page 1, 2, 3 when responding to setDetailItem UINavigatorContoller has a popToRootViewControllerAnimated message that can reset the previous navigation controller stack for each of the 3 navigation controllers. When I started learning ios development, I found setting up the controller hierarchies in code easier than using interface builder. IB is faster once you get the concepts. You can still create an IB nib controller for page1,2,3 root view controllers.

good reference: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457

like image 105
greg Avatar answered Oct 13 '22 22:10

greg