ストーリーボードに UIButton を作成し、ViewController に接続しました。プログラムでタップ時に「hintView」を表示させ、「hintView」の「OKButton」をタップして「hintView」をフェードさせたいと考えています。しかし、「OKButton」が押されるとクラッシュします: スレッド 1: "-[buttonToShowImgView.ViewController OKButtonPressed]: 認識されないセレクターがインスタンス 0x7f93d6806940 に送信されました"。ここで何が問題なのですか?
var hintView: UIImageView?
@IBAction func buttonTapped(_ sender: Any) {
showHint()
}
override func viewDidLoad() {
super.viewDidLoad()
}
func showHint() {
self.hintView = UIImageView(image: UIImage(named: "hintContent"))
hintView!.frame = view.frame
hintView!.isUserInteractionEnabled = true
hintView!.alpha = 1.0
view.addSubview(hintView!)
addOKButton()
}
func addOKButton() {
let OKButton = UIButton(type: .system)
OKButton.setTitle("OK!", for: UIControl.State.normal)
OKButton.setTitleColor(UIColor.red, for: .normal)
OKButton.titleLabel!.font = UIFont(name: "Avenir", size: 88)
OKButton.backgroundColor = UIColor.clear
OKButton.frame = CGRect(x: 0 , y: hintView!.bounds.height*3/4, width: hintView!.bounds.width, height: hintView!.bounds.height/6)
OKButton.addTarget(self, action: Selector(("OKButtonPressed")), for: UIControl.Event.touchUpInside)
hintView!.addSubview(OKButton)
}
func OKButtonPressed() {
self.hintView!.alpha = 0.0
}
}