ボタンが押された時にアラートを出したいのです。
アラートを出すことには成功したのですが、出したアラートがすぐに消えてしまいます。
何がいけないのでしょうか?
swift
1コード 2 3@IBAction func login(_ sender: Any) { 4 let alertController = UIAlertController(title: "エラー", message: "全ての枠を入力してください", preferredStyle: UIAlertController.Style.alert) 5 let okButton = UIAlertAction(title: "OK", style: UIAlertAction.Style.default) 6 alertController.addAction(okButton) 7 present(alertController, animated: true,completion: nil) 8 9}
全文です
swift
1import Foundation 2import UIKit 3 4class CommissionLoginViewController: UIViewController { 5 6 @IBOutlet weak var schoolName: UITextField! 7 @IBOutlet weak var id: UITextField! 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 11 12 } 13 14 @IBAction func login(_ sender: Any) { 15 16 print("あああ") 17 let alertController = UIAlertController(title: "エラー", message: "全ての枠を入力してください", preferredStyle: UIAlertController.Style.alert) 18 let okButton = UIAlertAction(title: "OK", style: UIAlertAction.Style.default) 19 alertController.addAction(okButton) 20 present(alertController, animated: true,completion: nil) 21 22 23 } 24 25 26 27} 28
回答2件
あなたの回答
tips
プレビュー