Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SplitView in Storyboard, can't connect delegate

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.

like image 779
Evan Cordell Avatar asked Jan 23 '12 16:01

Evan Cordell


1 Answers

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;
like image 81
Evan Cordell Avatar answered Jan 25 '23 18:01

Evan Cordell