質問編集履歴

1

2020/06/30 02:30

投稿

oeiqgfodgfhps
oeiqgfodgfhps

スコア35

test CHANGED
File without changes
test CHANGED
@@ -9,6 +9,56 @@
9
9
  テストのことを全く考えずにコードを書いてしまったので、テストしやすいコードの書き方という観点からも、こういう書き方にするべきというご意見がありましたら、ご指摘お願いいたします。
10
10
 
11
11
  ```swift
12
+
13
+
14
+
15
+ import UIKit
16
+
17
+ import FirebaseFirestore
18
+
19
+ import Firebase
20
+
21
+
22
+
23
+ class EditViewController: UIViewController,UITextFieldDelegate {
24
+
25
+
26
+
27
+ let db = Firestore.firestore()
28
+
29
+ var titleString = String()
30
+
31
+ var moneyString = String()
32
+
33
+ var descriptionString = String()
34
+
35
+ var documentIdString = String()
36
+
37
+
38
+
39
+ @IBOutlet weak var editButton: UIButton!
40
+
41
+ @IBOutlet weak var titleTextField: UITextField!
42
+
43
+ @IBOutlet weak var moneyTextField: UITextField!
44
+
45
+ @IBOutlet weak var descriptionTextField: UITextField!
46
+
47
+ override func viewDidLoad() {
48
+
49
+ super.viewDidLoad()
50
+
51
+ titleTextField.text = titleString
52
+
53
+ moneyTextField.text = moneyString
54
+
55
+ descriptionTextField.text = descriptionString
56
+
57
+ moneyTextField.keyboardType = UIKeyboardType.numberPad
58
+
59
+ }
60
+
61
+
12
62
 
13
63
  @IBAction func edit(_ sender: Any) {
14
64
 
@@ -32,18 +82,68 @@
32
82
 
33
83
  } else {
34
84
 
35
- let indexVC = self.storyboard?.instantiateViewController(identifier: "index") as! IndexViewController
36
-
37
- indexVC.modalPresentationStyle = .fullScreen
38
-
39
- self.present(indexVC, animated: true, completion: nil)
85
+ print("Document successfully updated")
40
86
 
41
87
  }
42
88
 
43
89
  }
44
90
 
91
+ let indexVC = self.storyboard?.instantiateViewController(identifier: "index") as! IndexViewController
92
+
93
+ indexVC.modalPresentationStyle = .fullScreen
94
+
95
+ present(indexVC, animated: true, completion: nil)
96
+
45
97
  }
46
98
 
47
99
 
48
100
 
101
+ func textFieldShouldReturn(_ textField: UITextField) -> Bool {
102
+
103
+ if titleTextField.text == ""||moneyTextField.text == ""{
104
+
105
+ editButton.isEnabled = false
106
+
107
+ }else{
108
+
109
+ editButton.isEnabled = true
110
+
111
+ }
112
+
113
+ titleTextField.resignFirstResponder()
114
+
115
+ moneyTextField.resignFirstResponder()
116
+
117
+ descriptionTextField.resignFirstResponder()
118
+
119
+ return true
120
+
121
+ }
122
+
123
+
124
+
125
+ override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
126
+
127
+ if titleTextField.text == ""||moneyTextField.text == ""{
128
+
129
+ editButton.isEnabled = false
130
+
131
+ }else{
132
+
133
+
134
+
135
+ editButton.isEnabled = true
136
+
137
+ }
138
+
139
+ titleTextField.resignFirstResponder()
140
+
141
+ moneyTextField.resignFirstResponder()
142
+
143
+ descriptionTextField.resignFirstResponder()
144
+
145
+
146
+
147
+
148
+
49
149
  ```