3

I am using Storyboards to create a container for an embedded viewController.

I would like to connected it to an IBOutlet of its parent viewController. I have defined the property on the parent and tried to ctl-drag to the container and I don't get an option to connect.

The pop-up doesn't show the property.

Any thoughts?

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Scott Sarnikowski
  • 1,461
  • 2
  • 14
  • 24

2 Answers2

12

If you're trying to make the outlet to the container view, you should be able to do that. It's just a normal UIView, so your IBOutlet property or ivar needs to be typed as UIView.

However, if you're trying to make the outlet between the parent controller and the embedded controller, you can't do that. IBOutlets can only be connected within a single controller, not across controllers. Instead of using an outlet, you can get a reference to that embedded controller in prepareForSegue -- that method will be called as soon as the parent controller is instantiated, and the child controller (the embedded one) will be the segue.destinationViewController.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • Excellent answer, I was looking all over the place how to get that child ViewController reference. Thank you :) – Fdo Sep 22 '15 at 15:07
  • More info on this approach here: http://stackoverflow.com/questions/13279105/access-container-view-controller-from-parent-ios – pkamb Jan 22 '16 at 18:11
0

In cording your said, You maybe forget to set Custom Class' asviewController` Class name.

shanegao
  • 3,562
  • 1
  • 18
  • 21
  • Yes... the contained viewController has my custom class. Interesting... the containerView is a UIView - so now it makes sense that I can connect to my outlet. I ctl-drag to the viewController and it still doesn't work. – Scott Sarnikowski Dec 23 '13 at 03:13