質問編集履歴
6
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -308,6 +308,10 @@
|
|
308
308
|
|
309
309
|
|
310
310
|
|
311
|
+
|
312
|
+
|
313
|
+
MainTabController内でdelegateで検索すると下記のものがありました。
|
314
|
+
|
311
315
|
```ここに言語を入力
|
312
316
|
|
313
317
|
// MainTabController.swift
|
@@ -337,5 +341,3 @@
|
|
337
341
|
}
|
338
342
|
|
339
343
|
```
|
340
|
-
|
341
|
-
MainTabController内でdelegateで検索すると上記のものがかかりました。
|
5
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -305,3 +305,37 @@
|
|
305
305
|
|
306
306
|
|
307
307
|
```
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
```ここに言語を入力
|
312
|
+
|
313
|
+
// MainTabController.swift
|
314
|
+
|
315
|
+
func checkIfUserIsLoggedIn() {
|
316
|
+
|
317
|
+
if Auth.auth().currentUser == nil {
|
318
|
+
|
319
|
+
print("現在のユーザーは:(Auth.auth().currentUser)です")
|
320
|
+
|
321
|
+
DispatchQueue.main.async {
|
322
|
+
|
323
|
+
let controller = LoginController()
|
324
|
+
|
325
|
+
// 子に設定されている(LoginController())を自身にもセット
|
326
|
+
|
327
|
+
controller.delegate = self
|
328
|
+
|
329
|
+
let nav = UINavigationController(rootViewController: controller)
|
330
|
+
|
331
|
+
nav.modalPresentationStyle = .fullScreen
|
332
|
+
|
333
|
+
self.present(nav, animated: true, completion: nil)
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
}
|
338
|
+
|
339
|
+
```
|
340
|
+
|
341
|
+
MainTabController内でdelegateで検索すると上記のものがかかりました。
|
4
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -232,8 +232,6 @@
|
|
232
232
|
|
233
233
|
}
|
234
234
|
|
235
|
-
// 質問1
|
236
|
-
|
237
235
|
updateForm()
|
238
236
|
|
239
237
|
}
|
@@ -270,8 +268,6 @@
|
|
270
268
|
|
271
269
|
dontHaveAccountButton.centerX(inView: view)
|
272
270
|
|
273
|
-
// 質問1 safeAreaLayoutGuideとは
|
274
|
-
|
275
271
|
dontHaveAccountButton.anchor(bottom: view.safeAreaLayoutGuide.bottomAnchor)
|
276
272
|
|
277
273
|
}
|
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -39,3 +39,273 @@
|
|
39
39
|
|
40
40
|
|
41
41
|
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
全体のコード
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
```ここに言語を入力
|
50
|
+
|
51
|
+
//
|
52
|
+
|
53
|
+
// LoginController.swift
|
54
|
+
|
55
|
+
// InstagramFirestoreTutorial
|
56
|
+
|
57
|
+
import UIKit
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
protocol AuthenticationDelegate:class {
|
62
|
+
|
63
|
+
func authenticationDidComplete()
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
class LoginController: UIViewController {
|
70
|
+
|
71
|
+
// MARK: - Properties
|
72
|
+
|
73
|
+
private var viewModel = loginViewModel()
|
74
|
+
|
75
|
+
// delegateを設定
|
76
|
+
|
77
|
+
weak var delegate: AuthenticationDelegate?
|
78
|
+
|
79
|
+
private let iconImage: UIImageView = {
|
80
|
+
|
81
|
+
let iv = UIImageView(image: #imageLiteral(resourceName: "Instagram_logo_white") )
|
82
|
+
|
83
|
+
iv.contentMode = .scaleAspectFill
|
84
|
+
|
85
|
+
return iv
|
86
|
+
|
87
|
+
}()
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
private let emailTextField: CustomTextField = {
|
92
|
+
|
93
|
+
//CustomTextField クラスのplaceholder: Stringの中にEmailが入っているのか。
|
94
|
+
|
95
|
+
let tf = CustomTextField(placeholder: "Email")
|
96
|
+
|
97
|
+
tf.keyboardType = .emailAddress
|
98
|
+
|
99
|
+
return tf
|
100
|
+
|
101
|
+
}()
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
private let passwordTextField: CustomTextField = {
|
106
|
+
|
107
|
+
let tf = CustomTextField(placeholder: "password")
|
108
|
+
|
109
|
+
tf.isSecureTextEntry = true
|
110
|
+
|
111
|
+
return tf
|
112
|
+
|
113
|
+
}()
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
private let loginButton: CustomUIButton = {
|
118
|
+
|
119
|
+
let button = CustomUIButton(title: "loginButton")
|
120
|
+
|
121
|
+
button.isEnabled = false
|
122
|
+
|
123
|
+
button.addTarget(self, action: #selector(handleLogin), for: .touchUpInside)
|
124
|
+
|
125
|
+
return button
|
126
|
+
|
127
|
+
}()
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
private let forgotPasswordButton: UIButton = {
|
132
|
+
|
133
|
+
let button = UIButton(type: .system)
|
134
|
+
|
135
|
+
button.attributedTitle(firstPart: "Forgot you password? ", secondPart: "Get help signiing in.")
|
136
|
+
|
137
|
+
return button
|
138
|
+
|
139
|
+
}()
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
private let dontHaveAccountButton: UIButton = {
|
144
|
+
|
145
|
+
let button = UIButton(type: .system)
|
146
|
+
|
147
|
+
button.attributedTitle(firstPart: "Don't have an account", secondPart: "Sign Up")
|
148
|
+
|
149
|
+
button.addTarget(self, action: #selector(handleShowSignUp), for: .touchUpInside)
|
150
|
+
|
151
|
+
return button
|
152
|
+
|
153
|
+
}()
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
// MARK: - Lifecycle
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
override func viewDidLoad() {
|
162
|
+
|
163
|
+
super.viewDidLoad()
|
164
|
+
|
165
|
+
view.backgroundColor = .systemPink
|
166
|
+
|
167
|
+
configureUI()
|
168
|
+
|
169
|
+
configureNotificationObservers()
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
//
|
174
|
+
|
175
|
+
// override func viewDidAppear(_ animated: Bool) {
|
176
|
+
|
177
|
+
// if
|
178
|
+
|
179
|
+
// }
|
180
|
+
|
181
|
+
//
|
182
|
+
|
183
|
+
// MARK: - Actions
|
184
|
+
|
185
|
+
@objc func handleLogin() {
|
186
|
+
|
187
|
+
guard let email = emailTextField.text else { return }
|
188
|
+
|
189
|
+
guard let password = passwordTextField.text else { return }
|
190
|
+
|
191
|
+
AuthService.logUserIn(withEmail: email, password: password) { (result, error) in
|
192
|
+
|
193
|
+
if let error = error {
|
194
|
+
|
195
|
+
print("ログインエラー: (error.localizedDescription)")
|
196
|
+
|
197
|
+
return }
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
self.delegate?.authenticationDidComplete()
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
@objc func handleShowSignUp() {
|
208
|
+
|
209
|
+
// インスタンス化
|
210
|
+
|
211
|
+
let controller = RegistrationController()
|
212
|
+
|
213
|
+
//
|
214
|
+
|
215
|
+
controller.delegate = delegate
|
216
|
+
|
217
|
+
navigationController?.pushViewController(controller, animated: true)
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
@objc func textDidChange(sender: UITextField) {
|
224
|
+
|
225
|
+
if sender == emailTextField{
|
226
|
+
|
227
|
+
viewModel.email = sender.text
|
228
|
+
|
229
|
+
} else {
|
230
|
+
|
231
|
+
viewModel.password = sender.text
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
// 質問1
|
236
|
+
|
237
|
+
updateForm()
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
func configureUI() {
|
244
|
+
|
245
|
+
configureGradientLayer()
|
246
|
+
|
247
|
+
navigationController?.navigationBar.isHidden = true
|
248
|
+
|
249
|
+
navigationController?.navigationBar.barStyle = .black
|
250
|
+
|
251
|
+
view.addSubview(iconImage)
|
252
|
+
|
253
|
+
iconImage.centerX(inView: view)
|
254
|
+
|
255
|
+
iconImage.setDimensions(height: 80, width: 120)
|
256
|
+
|
257
|
+
iconImage.anchor(top: view.safeAreaLayoutGuide.topAnchor,paddingTop: 32)
|
258
|
+
|
259
|
+
let stack = UIStackView(arrangedSubviews: [emailTextField,passwordTextField,loginButton,forgotPasswordButton])
|
260
|
+
|
261
|
+
stack.axis = .vertical
|
262
|
+
|
263
|
+
stack.spacing = 20
|
264
|
+
|
265
|
+
view.addSubview(stack)
|
266
|
+
|
267
|
+
stack.anchor(top: iconImage.bottomAnchor, left: view.leftAnchor, right: view.rightAnchor, paddingTop: 32, paddingLeft: 32, paddingRight: 32)
|
268
|
+
|
269
|
+
view.addSubview(dontHaveAccountButton)
|
270
|
+
|
271
|
+
dontHaveAccountButton.centerX(inView: view)
|
272
|
+
|
273
|
+
// 質問1 safeAreaLayoutGuideとは
|
274
|
+
|
275
|
+
dontHaveAccountButton.anchor(bottom: view.safeAreaLayoutGuide.bottomAnchor)
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
func configureNotificationObservers() {
|
282
|
+
|
283
|
+
emailTextField.addTarget(self, action: #selector(textDidChange), for: .editingChanged)
|
284
|
+
|
285
|
+
passwordTextField.addTarget(self, action: #selector(textDidChange), for: .editingChanged)
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
// MARK: - FormViewModel
|
294
|
+
|
295
|
+
extension LoginController: FormViewModel {
|
296
|
+
|
297
|
+
func updateForm() {
|
298
|
+
|
299
|
+
loginButton.backgroundColor = viewModel.buttonBackgroundColor
|
300
|
+
|
301
|
+
loginButton.setTitleColor(viewModel.buttonTitleColor, for: .normal)
|
302
|
+
|
303
|
+
loginButton.isEnabled = viewModel.formIsValid
|
304
|
+
|
305
|
+
}
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
```
|
2
追記
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
delegateの理解
|
1
|
+
delegateの理解が正しいか見てほしい
|
test
CHANGED
File without changes
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
子に設定されているdelegateについて以下の自分の認識が合っているか見てほしいです。
|
2
|
+
|
3
|
+
|
2
4
|
|
3
5
|
前提:
|
4
6
|
|
5
7
|
・`LoginController`:子 `MainTabController`:親
|
6
8
|
|
7
|
-
・画像の`self.delegate?.authenticationDidComplete()`は`LoginController`に設定されているコード
|
9
|
+
・画像の`self.delegate?.authenticationDidComplete()`は子の`LoginController`に設定されているコード
|
8
10
|
|
9
11
|
|
10
12
|
|
11
13
|
自分の認識:
|
12
14
|
|
13
|
-
・以下の画像
|
15
|
+
・以下の画像の`self.delegate?.authenticationDidComplete()`は`MainTabController`にある`authenticationDidComplete`メソッドを呼び出しいる。
|
14
16
|
|
15
17
|
|
16
18
|
|