0

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?

Community
  • 1
  • 1
NYC Tech Engineer
  • 1,845
  • 2
  • 22
  • 23
  • What's your question, exactly? – livingtech Dec 02 '14 at 16:24
  • My question is still the same as what I asked originally, but I just provided details as to what I've done so far to give people some context. – NYC Tech Engineer Dec 02 '14 at 16:28
  • Not an answer, but when I change "self.detailViewController = detailViewController" to "_detailViewController = detailViewController", the infinite loop stops. Why is this? – NYC Tech Engineer Dec 02 '14 at 19:44
  • Now, during the moment, when I pass splitViewController.viewControllers.lastObject to detailViewManager.detailViewController, I am passing a nil object. I assumed that if I set the class of the detail view controller in interface builder, that that would be the second object of the viewControllers array property on the splitViewController. Is this wrong? – NYC Tech Engineer Dec 02 '14 at 19:52
  • When I do a "po splitViewController.viewControllers" in the debugger, I get the below: <__NSArrayI 0x178029ec0>( , ) How would I get to the view controller on the stack? – NYC Tech Engineer Dec 02 '14 at 19:55

0 Answers0