私はIBActionにリンクされたデフォルトのUIButtonを持っています(内部をタッチアップ)。これは正常に動作するので、接続が正常であることがわかります。 UIButtonクラスをカスタムボタンに変更すると、IBActionはもうトリガーされません。以下は私のカスタムUIButtonのコードです。これがなぜ起こっているのか?カスタムUIButton - IBActionが機能しない
import UIKit
@IBDesignable
class PrimaryButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
initView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initView()
}
private func initView() {
let view = viewFromNibForClass()
view.frame = bounds
view.autoresizingMask = [
UIViewAutoresizing.flexibleWidth,
UIViewAutoresizing.flexibleHeight
]
addSubview(view)
}
private func viewFromNibForClass() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
return view
}
}