'Unexpectedly found nil of optional value when addtarget of button
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
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
}
}
Solution 1:[1]
You are using
@IBOutlet weak var buttonSandK : Button!
but I think You should change it to
@IBOutlet weak var buttonSandK : UIButton!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

