textfieldにaddTarget
すれば入力が変更されるたびに呼ばれるので、そちらでラベルに反映すればよいと思いますよ。
swift
1
2@objc func changeCountTextField(_ sender: UITextField) {
3 if let text = sender.text {
4 print(text)
5 }
6}
7
8@objc func changeWeightTextField(_ sender: UITextField) {
9 if let text = sender.text {
10 print(text)
11 }
12}
13
14@IBAction func btr(_ sender: Any) {
15 let alert = UIAlertController(title: "値を入力してください", message: "\n\n\n\n\n\n\n\n", preferredStyle: .alert)
16 // テキストフィールドを追加
17 alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
18 textField.placeholder = "回数を入力してください。"
19 textField.addTarget(self, action: #selector(self.changeCountTextField(_:)), for: .editingChanged)
20 })
21 //二個目
22 alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
23 textField.placeholder = "重量を入力してください。"
24 textField.addTarget(self, action: #selector(self.changeWeightTextField(_:)), for: .editingChanged)
25 })
26
27 let saveAction = UIAlertAction(title: "OK", style: .default) { (action:UIAlertAction!) -> Void in
28 //self.mytableView.reloadData()
29 }
30 let cancelAction = UIAlertAction(title: "キャンセル", style: .default) { (action:UIAlertAction!) -> Void in
31 }
32
33 //PickerView
34 pickerView = UIPickerView(frame:CGRect(x:0, y:50, width:view.bounds.width*0.6, height:300)) // 配置、サイズ
35 pickerView.frame = CGRect(x:0, y:0, width:view.bounds.width*0.7, height:280)
36 pickerView.dataSource = self
37 pickerView.delegate = self
38 alert.view.addSubview(pickerView)
39
40 alert.addAction(saveAction)
41 alert.addAction(cancelAction)
42
43 present(alert, animated: true, completion: nil)
44}
45
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/08 09:31 編集
2018/07/08 11:52
退会済みユーザー
2018/07/08 15:22
退会済みユーザー
2018/07/09 15:17 編集