4

We have a certain behaviour we require in our UISplitViewController application. We have the following hierarchy of 3 views

  • FormOneViewController - TableViewController intialised in the MasterView
  • FormTwoViewcontroller - TableViewCotnroller initalised in detailView
  • FormThreeViewcontroller - not yet displayed.

When the user selects an item in FormTwoViewController we want FormThreeViewCOntroller to appear in the detailView, and FormTwoViewController (the current detail view) to become the masterView.

We also need to have a back button on the detail view to return up the stack of viewcontrollers. So when back is pressed, FormTwoViewController becomes the detailView and FormOneViewController becomes the master view again.

We have tried to implement this using the UISPlitViewcontroller and with a masterNavigationController and a detailNavigationController. We have the initial phase working where the views are displayed correctly when the app starts, we select the FormTwoViewController Item and it pushes FormThreeViewController onto the detailNavigationController and FormTwoViewController is pushed onto the masterNavigationController stack.

The problem we now have is twofold

  1. when the backbutton is pressed in the detail view controller it does nothing. it appears the handlers have got disconnected or something.
  2. We do not get a button in the portrait mode to display the masterview in a popover.

Has anyone got any examples of how to do this or any help wuld be appreciated.

Jay
  • 19,649
  • 38
  • 121
  • 184
chris baxter
  • 41
  • 1
  • 2
  • It would be helpful if you'd show some code. "It pushes FormThreeViewController onto the detailNavigationController and FormTwoViewController is pushed onto the masterNavigationController stack." It's crucial to know exactly how you're doing that. As for the popover button, it's up to you to implement the split view controller's delegate to obtain that; are you? – matt Jan 10 '11 at 00:50

1 Answers1

9

yes you can do that but u need to create seperate view controller for master and detail create new project as split view controller and remove split view from xib so that we are creating split view from code .

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after app launch.
    self.splitViewController =[[UISplitViewController alloc]init];
    self.rootViewController=[[RootViewController alloc]init];
    self.detailViewController=[[DetailViewController alloc]init];

    UINavigationController *rootNav=[[UINavigationController alloc]initWithRootViewController:rootViewController];
    UINavigationController *detailNav=[[UINavigationController alloc]initWithRootViewController:detailViewController];

    // Add the split view controller's view to the window and display.
    self.splitViewController.viewControllers=[NSArray arrayWithObjects:rootNav,detailNav,nil];
    self.splitViewController.delegate=detailViewController;
    [self.window addSubview:self.splitViewController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

where rootviewcontroller is ur form one and detail view controller is ur form two.

in detail view controller ie ur form two create class variable SplitViewAppDelegate *appDelegate; //id ur app delegate variable set property and synthesize it.

then in ur form two

- (void)viewDidLoad {
self.appDelegate = (SplitViewAppDelegate *)[[UIApplication sharedApplication] delegate];
}

and finally while pushing ur form three

- (IBAction)pushViewController:(id)sender{
    NSLog(@"%@",self.appDelegate.splitViewController.viewControllers);
    RootLevel1 *rootLevel1 =[[RootLevel1 alloc]init];//create form 1 root vc and assign form 1 vc
    DetailLevel1 <UISplitViewControllerDelegate>*detailLevel1=[[DetailLevel1 alloc]init];

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] 
                                   initWithTitle: @"Home" 
                                   style:UIBarButtonItemStylePlain 
                                   target:self 
                                   action:@selector(home)];
    rootLevel1.navigationItem.leftBarButtonItem=backButton;
    [self.appDelegate.splitViewController viewWillDisappear:YES];
    [[self.appDelegate.splitViewController.viewControllers objectAtIndex:0] pushViewController:rootLevel1 animated:YES];
    [[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] pushViewController:detailLevel1 animated:YES];
    self.appDelegate.splitViewController.delegate = detailLevel1;
    [self.appDelegate.splitViewController viewWillAppear:YES];

}

and for poping view controller

-(void)home {
    [self.splitViewController viewWillDisappear:YES];
    [[self.appDelegate.splitViewController.viewControllers objectAtIndex:0]popViewControllerAnimated:YES];  
    [[self.appDelegate.splitViewController.viewControllers objectAtIndex:1]popViewControllerAnimated:YES];  
    UIViewController <UISplitViewControllerDelegate>*viewController=[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] visibleViewController];
    self.splitViewController.delegate=viewController;   
    [self.splitViewController viewWillAppear:YES];

}

set ur splitview delgeate accordingly.

Kshitiz Ghimire
  • 1,716
  • 3
  • 18
  • 37
  • you can download code from here http://kshitizghimire.com.np/uisplitviewcontroller-multipledetailviews-with-navigation-controller/ – Kshitiz Ghimire Mar 10 '11 at 04:50