You must implement the UISplitViewControllerDelegate. The easiest way is to have your own MySplitViewController class and designate yourself as a delegate in viewDidLoad:
self.delegate = self;
First, you might want showDetailViewController to look something like this:
- (BOOL) splitViewController:(UISplitViewController*)splitViewController showDetailViewController:(UIViewController*)vc sender:(id)sender { if (splitViewController.collapsed) { [(UINavigationController*)splitViewController.viewControllers[0]) pushViewController:vc animated:YES]; } else { self.viewControllers = @[ self.viewControllers.firstObject, vc ]; } return YES; }
This should take care of the correct presentation of the detail representation in both orientations.
Next, you must implement the following delegation method, similar to this:
- (UIViewController*) splitViewController:(UISplitViewController*)splitViewController separateSecondaryViewControllerFromPrimaryViewController:(UIViewController*)primaryViewController { UINavigationController* nc = primaryViewController; UIViewController* detailVC = nc.viewControllers.lastObject; return detailVC; }
This method is your chance to take everything you want from the main controller and return it as the controller of the detailed views. The above sample example is pretty simple, you may have to go through the viewControllers navigation and select everything from a specific view controller (if you clicked on the view details).
In any case, it would actually be beneficial to spend some time and read: a link to the UISplitViewController class and especially the UISplitViewControllerDelegate Protocol Reference This will be much clearer. If you need a shortcut, take a look at the Xcode splitting controller template project. It should also contain a hint or an exact solution to your problem.
source share