Reputation: 9
I would like to update my UILabel
on click the button of ContainerView
contains table ViewController
. When I try to do this UILabel's
outlets reference shows nil value exception. I am using Swift3 with Xcode8
Upvotes: 0
Views: 322
Reputation: 26385
Most probably the problem you are seeing is due to the fact that the view that owns this label on another view controller is still not loaded.
This happens often, basically because views owned by a view controller are instantiated in a lazy manner, this means that they are loaded only when required.
To fix that before setting the value on the label, just preload the view by doing something like.
_ = another_viewcontroller_instance.view
In this way you are forcing the destination view controller to load the view and creating all the necessary connection on the xib.
Even if this fix works, this is not a good way to deal with this kind of pattern (sending info from a VC to another), but since you didn't gave us any further detail this is the only solution I have.
Upvotes: 2