ここはあなたのエラー報告をするところではありません。
実装中に以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
Use of unresolved identifier 'onClickMyButton'
該当のソースコード
Swift
1class ViewController: UIViewController { 2 3 override func viewDidLoad() { 4 super.viewDidLoad() 5 6 // Viewの背景を設定する 7 self.view.backgroundColor = UIColor.cyan 8 9 // ボタンを定義する 10 let myButton: UIButton = UIButton() 11 let buttonWidth: CGFloat = 200 12 let buttonHeight: CGFloat = 40 13 let posX: CGFloat = (self.view.bounds.width - buttonWidth)/2 14 let posY: CGFloat = 200 15 16 myButton.frame = CGRect(x: posX, y: posY, width: buttonWidth, height: buttonHeight) 17 myButton.backgroundColor = UIColor.red 18 myButton.layer.masksToBounds = true 19 myButton.layer.cornerRadius = 20.0 //角丸くする 20 myButton.setTitle("UIAlertを起動", for: .normal) 21 myButton.setTitleColor(UIColor.white, for: .normal) 22 myButton.addTarget(self, action: #selector(onClickMyButton(_:)), forControlEvents: .TouchDown) 23 24 25 // ボタンをviewに追加する 26 self.view.addSubview(myButton) 27 28 } 29 30 // ボタンイベント 31 internal func onClickMyButton(sender: UIButton) { 32 33 // UIAlertControllerを作成 34 let myAlert: UIAlertController = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert) 35 36 // OKのアクションを作成 37 let myOkAction = UIAlertAction(title: "OK", style: .default) { action in 38 print("Action OK!") 39 } 40 41 // OKのアクションを追加 42 myAlert.addAction(myOkAction) 43 44 // UIAlertを発動する 45 present(myAlert, animated: true, completion: nil) 46 47 } 48 49 override func didReceiveMemoryWarning() { 50 super.didReceiveMemoryWarning() 51 } 52 53 54}
補足情報(FW/ツールのバージョンなど)
Xcode 10.1
回答1件
あなたの回答
tips
プレビュー