Initially, I set up a UISplitViewController by hand in Storyboards. I embedded both the master and detail view controller with a navigation controller.
My only problem is having the navigation pane bar button item show up in portrait mode so that the user can summon the left pane tableview.
I resorted to using Apple's Multiple View Detail code, doing pretty much what the fellow in this link did: UISplitView with Multiple Detail Views (with Storyboard)
In Storyboard, I set the master and detail view controllers explicitly. I was also able to set the delegate of the splitViewController using Interface Builder using an NSObject. But the delegate (below) never gets its method called below:
// "DetailViewManager.h"
-(void)setDetailViewController:(UIViewController<SubstitutableDetailViewController> *)detailViewController
{
self.detailViewController.navigationPaneBarButtonItem = nil;
self.detailViewController = detailViewController;
self.detailViewController.navigationPaneBarButtonItem = self.navigationPaneButtonItem;
UIViewController *navigationViewController = [self.splitViewController.viewControllers objectAtIndex:0];
NSArray *viewControllers = [NSArray arrayWithObjects:navigationViewController, self.detailViewController, nil];
self.splitViewController.viewControllers = viewControllers;
if (self.navigationPopoverController) {
[self.navigationPopoverController dismissPopoverAnimated:YES];
}
}
The initial detail view controller never gets its method to set the navigation bar button item called either:
// "DetailViewController.h"
-(void)setNavigationPaneBarButtonItem:(UIBarButtonItem *)navigationPaneBarButtonItem
{
if (navigationPaneBarButtonItem != self.navigationPaneBarButtonItem) {
if (navigationPaneBarButtonItem) {
[self.navigationController.toolbar setItems:[NSArray arrayWithObject:navigationPaneBarButtonItem] animated:NO];
} else {
[self.navigationController.toolbar setItems:nil];
}
}
}
Whenever I try to set the detail view controller programmatically when I first set the splitViewController as rootViewController, I get into an infinite loop with the first delegate method I just mentioned above:
// "LogVC.h"
- (IBAction)loginButtonPressed:(id)sender {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UISplitViewController *splitViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"splitViewController"];
DetailViewManager *detailViewManager = (DetailViewManager *)splitViewController.delegate;
detailViewManager.detailViewController = splitViewController.viewControllers.lastObject;
UIViewAnimationOptions transitionAnimation;
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
transitionAnimation = UIViewAnimationOptionTransitionFlipFromLeft;
} else {
transitionAnimation = UIViewAnimationOptionTransitionFlipFromTop;
}
[UIView transitionWithView:appDelegate.window duration:0.75 options:transitionAnimation animations:^{
appDelegate.window.rootViewController = splitViewController;
} completion:nil];
}
I guess what I couldn't wrap my head around in Apple's provided code is when the delegate method is ever called, because I don't remember them configuring the detail view controller, whereas I set mine up in Storyboard, and then programmatically.
UPDATE:
I've been able to pass the instantiated view controller within Storyboard as the detail view controller to my detail view manager with the code below:
// "LogVC.h"
UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"identifier"];
DetailViewManager *detailViewManager = (DetailViewManager *)splitViewController.delegate;
detailViewManager.detailViewController = detailViewController;
The detail view gets set up correctly, and is displayed. But I'm still missing the navigation pane bar button item at the top left corner. In fact, I'm missing the entire navigation bar at the top, is this normal?
This is the code I used in the detail view controller to set up the navigation pane bar button item:
// "DetailViewController.h"
-(void)setNavigationPaneBarButtonItem:(UIBarButtonItem *)navigationPaneBarButtonItem
{
if (navigationPaneBarButtonItem != _navigationPaneBarButtonItem) {
if (navigationPaneBarButtonItem) {
[self.navigationController.toolbar setItems:[NSArray arrayWithObject:navigationPaneBarButtonItem] animated:NO];
} else {
[self.navigationController.toolbar setItems:nil];
}
_navigationPaneBarButtonItem = navigationPaneBarButtonItem;
}
}
I have the feeling that I can't simply add the navigationPaneBarButtonItem to self.navigationController.toolbar this way, that I must create my own toolbar. Is this correct?