Unexpectedly found nil of optional value when addtarget of button

96 Views Asked by At

There is an error in addTarget of buttonSandK

I Check the reference outlet and it's connected+

if i remove addtarget, the code run. What am i missing here

enter image description here

public protocol tenorFooterDelegate: AnyObject{
    func tapSK(message : String)
}

class TenorFooterView: UICollectionReusableView {
    @IBOutlet weak var buttonSandK : Button!
    
    weak var delegate : tenorFooterDelegate!
    var message : String?
    override func awakeFromNib() {
        super.awakeFromNib()
        
        buttonSandK.addTarget(self, action: #selector(onTapLaunch(_:)), for: .touchUpInside)
        
       
    }
    
    @objc
    func onTapLaunch(_ sender: UIButton){
       // self.delegate.tapSK(message: message ?? "")
    }
    
    func configure(with data: String) {
       message = data
    }
}
1

There are 1 best solutions below

0
On

You are using

@IBOutlet weak var buttonSandK : Button!

but I think You should change it to

@IBOutlet weak var buttonSandK : UIButton!