Reputation: 263
I have a custom button designed using xib file like this:
and I connect it to my storyboard like this:
but when I run the app, I got runtime error complaining that IBOutlet ivRightIcon is nil
@IBInspectable var rightIcon: UIImage? = nil{
didSet{
ivRightIcon.image = rightIcon
}
}
}
My outlet is connected in xib file correctly I'm using Swift 3 and xCode 8.2.1 Please help!
Upvotes: 3
Views: 5489
Reputation: 655
I solved that error by modifying the outlets values in viewWillAppear
instead of viewDidLoad
. This way the outlets is fully loaded when accessed.
Upvotes: 0
Reputation: 263
I managed to solve this. I should set the View class as UIButton and File's Owner as my custom button class
Upvotes: 4
Reputation: 5823
I think you need to connect your xib with file responder and assign class to file responder instead of view. then connect IBOutlet of xib to the class.
Upvotes: 1