Question

I have an iPad interface defined in a storyboard, with a SplitViewController. I want to set the delegate of the SplitViewController to point to the detail controller, but IB won't allow that connection to be made.

  • Putting an "object" object and changing the class to that of my detail controller makes the delegate point to a different instance of the detail controller than the one displayed.
  • My attempts to connect it manually (in didFinishLaunching) in the app delegate were fruitless, the delegate was still nil.
  • Changing the delegate to the AppDelegate and implementing the protocol there worked, but passing messages to the detail controller didn't work (even though I verified that I was referencing the same instance).

Nothing works. I can set self.splitViewController.delegate = self when detail view loads, and then it becomes the delegate with no problem. But I miss any delegate calls that happen before that point.

For context, I need to get the splitviewcontroller's delegate calls so that I can show a button in the detailview to show a popover, as is standard practice. Right now, if the app is launched in portrait, it has to be rotated to landscape and then back for the button to show.

I've done this with "normal" xibs with no issue. It seems to be a special case of the more general problem of not being allowed to connect outlets across scenes in a storyboard.

Was it helpful?

Solution

I have no idea why this worked this time and not the first 80 times, but I added this to my AppDelegate:

UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top