質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1378閲覧

UIAlertControllerでアラートを表示したい。

aotanuki

総合スコア13

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2019/02/20 14:06

実装中に以下のエラーメッセージが発生しました。

発生している問題・エラーメッセージ

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fuzzball

2019/02/21 00:54

ここはあなたのエラー報告をするところではありません。
aotanuki

2019/02/21 04:01 編集

ご丁寧に回答ありがとうございます。次回から単なるエラー報告はもうしません。
guest

回答1

0

ベストアンサー

swift

1@objc 2internal func onClickMyButton(_ sender: UIButton)

投稿2019/02/21 00:53

fuzzball

総合スコア16731

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問