Reputation: 190
I created a custom uibutton from xib and was using the this customButton inside a viewController xib file. This custom view has a subview UILabel named buttonLabel.
I've set the class of the customButton xib correctly and have set the outlet for it in the viewController. When viewDidLoad in the viewController, I am trying to access self.customButton.buttonLabel like so:
self.customButton.buttonLabel.text = "something"
the result is a runtime crash with the following message:
fatal error: unexpectedly found nil while unwrapping an Optional value
The reason is that self.customButton.buttonLabel is nil at that time. I've made sure the xib file has the same name as the swift class name as well. What could be the issue?
Thanks in advance
Upvotes: 1
Views: 278