0
votes

I'm transitioning my app to iOS 8, and I've decided to use a SplitViewController because its new functionality finally allows me to do what I want. I present the SVC modally on iPad, and the SVC is the root view controller of the full-screen cover vertical transition. From the presenting view controller:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    plotSplitViewController = segue.destinationViewController;

    plotViewController = (PlotViewController *)[[[segue.destinationViewController viewControllers] objectAtIndex:1] topViewController];
    plotViewController.inventory = _inventory;

    if ([plotViewController view]) [plotViewController setPlot:selectedPlot];
}

Then I manually make connections in the PlotSplitViewController:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.delegate = self;

    // set up controllers
    layoutNavigationController = [self.viewControllers objectAtIndex:1];
    plotViewController = (PlotViewController *)[layoutNavigationController topViewController];
    plotViewController.delegate = self;

    // configure split view
    [self showInfoPane:NO withTable:infoTableViewController];
    self.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
}

So both the master and the detail get view controllers inside UINavigationControllers (to take advantage of the free toolbar resizing, plus the master pushes a table view hierarchy).

Everything seems fine; the views load as they're supposed to, the delegate method from PlotViewController functions correctly, etc. But as you can see, I assign the Split View Controller to be its own delegate...but it won't respond to any of its own methods, so I can't customize its behavior. I checked to make sure it's set correctly:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(@"split view %@ did appear, delegate: %@", self, self.delegate);
}

And it returns the same object (itself) for both values. Is this just a no-no? I read that you can assign a SplitViewController as its own delegate, and I think an object can be a delegate for more than one other object, right? It can certainly implement protocols for more than one. So why is my SplitViewController not able to receive delegate methods for itself? I have NSLogs in all of them, and none are ever called.

1

1 Answers

0
votes

Turns out it works if you make your custom view controller a subclass of UIViewController, and add a UISplitViewController programmatically, as a child view controller. Make your VC its delegate, and you can make it behave however you want.