Error reporting and resolution of #selector above swift5
The version of swift has changed a lot recently. If you add an event to a button, you must be very skilled in OC. How do you define functions and pass parameters in
swift
let btn = UIButton()
btn.tag = 2
btn.addTarget(self, action: #selector(buttonClick(button:)), for: .touchUpInside)
@objc func buttonClick(button: UIButton) {
button.isSelected = true
print(btn.tag!)
print("\(btn.tag)")
}
The custom method must be preceded by @ objc to follow the OC mechanism, otherwise an error will be reported