1

I have a ViewController with a ScrollView in it, which has 2 ContainerViews in it. Now, every ContainerView loads a ViewController. And in this ViewControllers (SubController from the ContainerViews) its impossible to do Outlets. I get the little circles at the outlets, so the reference exists, but setting the text of a label for example, always results in the following error:

fatal error: unexpectedly found nil while unwrapping an Optional value

I've done the connection 10 times, with all possible names. Restarted xcode multiple times, still not working.

This answer could help: https://stackoverflow.com/a/28479934/2414069

EDIT: (below code is pseudo, everything is in the place it should..)

@IBOutlet weak var pinInfo_name: UILabel!
@IBOutlet weak var pinInfo_address: UITextView!
@IBOutlet weak var pinInfo_comment: UITextView!

self.pinInfo_name.text = defaults.stringForKey("activePin_name")!
self.pinInfo_address.text = defaults.stringForKey("activePin_address")!
self.pinInfo_comment.text = defaults.stringForKey("activePin_comment")!

SOULUTION: Ok I slept about it, and found my error within 10 minutes: I wanted to change the .text properties from a object I created in another ViewController. I still have no Idea how to do that, buts thats a story for another time.

tl dr

Access right

Community
  • 1
  • 1
Eric Random
  • 158
  • 9

1 Answers1

0

As the link in your question points out, having multiple view controllers in your storyboard with the same class could cause this. Did you check that:

  1. The child view controllers do not have the same class as each other
  2. The child view controllers do not have the same class as the parent view controller

I made a test project and the I could connect the outlets of the UILabels in the child view controller to their respective UIViewController subclasses without any problem.

Here's my example:

enter image description here

paulvs
  • 11,963
  • 3
  • 41
  • 66