yes, you can do it, but you need to create a separate view controller for the master and parts, create a new project as a split view controller and remove the split view from xib so that we create a split view from the 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 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 an urn format and the detailed view controller is ur forming two.
in the detail view controller, i.e. ur form two create class variable SplitViewAppDelegate * appDelegate; // delegate id id ur app set the property and synthesize it.
then in ur form two
- (void)viewDidLoad { self.appDelegate = (SplitViewAppDelegate *)[[UIApplication sharedApplication] delegate]; }
and finally by clicking ur, create 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 to start the 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.
source share