Search code examples
iphoneobjective-ciosipaduisplitviewcontroller

Change Detail View on selecting tab of Master view in split view controller


I am new to ipad development. In my application i have created splitview like the below image. In this how can i call another detailview controller when tabbar on the left pane selection changes??

Please help me..

My Splitview Screen


Solution

  • You can simply replace the VC at index 1 of the UISplitViewController's viewControllers property. Try something like-

    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    {
         UIViewController* myReplacementVC = nil;
          if(viewController == VC1)
               myReplacementVC = myReplacementVC1;
          else
               myReplacementVC = myReplacementVC2; 
    
          NSMutableArray* arr = [[NSMutableArray alloc] initWithArray:splitVC.viewControllers];
              [arr replaceObjectAtIndex:1 withObject:myReplacementVC]; //index 1 corresponds to the detail VC
              splitVC.viewControllers = arr;
              [arr release];
        }