I have a viewController
with two embedded
viewControllers
through containers
. I then created outlets
from the parent viewController's
containers
to the parent class
. I want to either hide or show the containers
depending on certain conditionals.
But if I simply write:
@IBOutlet var twoArmsContainer: UIView! {
didSet {
print("SETTING TWO ARM")
}
}
override func viewDidLoad() {
super.viewDidLoad()
twoArmsContainer.isHidden = true //container is nil
}
Then it crashes with twoArmsContainer
being nil
after the print in didSet
has been triggered. How is it possible that the outlet is set, but then becomes nil
? I have tried hiding it inside didSet
and that works fine:
@IBOutlet var twoArmsContainer: UIView! {
didSet {
print("SETTING TWO ARM")
twoArmsContainer.isHidden = true //WORKS
}
}
What else can I say? The class
I'm working in inherits
from another class
so there is a super.viewDidLoad
. Not sure if that is relevant. I tried putting the outlets
in the super class
but with the same results. I also tried removing and readding the outlets
again. Have never experienced this problem before. Let me know if I should show more code; perhaps the entire class
. Not really sure what's relevant as I'm clueless of where to start.