質問編集履歴

1

解決いたしましたので削除します。

2021/04/07 01:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -13,373 +13,3 @@
13
13
 
14
14
 
15
15
  この問題にご存知の方、どうかご助言をいただけたら幸いです。
16
-
17
-
18
-
19
- ```ここに言語を入力
20
-
21
- import UIKit
22
-
23
- import RealmSwift
24
-
25
-
26
-
27
- private let reuseIdentifier = "EditProfileCell"
28
-
29
-
30
-
31
- protocol EditProfileControllerDelegate: class {
32
-
33
- func controller(_ controller: EditProfileController, wantsToUpdate user: User)
34
-
35
- }
36
-
37
-
38
-
39
- class EditProfileController: UITableViewController {
40
-
41
-
42
-
43
- // MARK: - Properties
44
-
45
-
46
-
47
- private var user: Results<User>!
48
-
49
- private lazy var headerView = EditProfileHeader(user: user)
50
-
51
- private let imagePicker = UIImagePickerController()
52
-
53
- private var userInfoChange = false
54
-
55
- private let realm = try! Realm()
56
-
57
-
58
-
59
- private var imageChanged: Bool {
60
-
61
- return selectedImage != nil
62
-
63
- }
64
-
65
-
66
-
67
- weak var delegate: EditProfileControllerDelegate?
68
-
69
-
70
-
71
- private var selectedImage: UIImage? {
72
-
73
- didSet {
74
-
75
- headerView.profileImageView.image = selectedImage
76
-
77
- }
78
-
79
- }
80
-
81
-
82
-
83
- // MARK: - Lifecycle
84
-
85
-
86
-
87
- init(user: Results<User>!){
88
-
89
- self.user = user
90
-
91
- super.init(style: .plain)
92
-
93
- }
94
-
95
-
96
-
97
- required init?(coder: NSCoder) {
98
-
99
- fatalError("init(coder:) has not been implemented")
100
-
101
- }
102
-
103
-
104
-
105
- override func viewDidLoad() {
106
-
107
- super.viewDidLoad()
108
-
109
- configureUI()
110
-
111
- configureImagePicker()
112
-
113
- }
114
-
115
-
116
-
117
- override func viewWillDisappear(_ animated: Bool) {
118
-
119
- super.viewWillDisappear(animated)
120
-
121
- NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillChangeFrameNotification, object: nil)
122
-
123
- NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
124
-
125
- }
126
-
127
-
128
-
129
- // MARK: - Selectors
130
-
131
-
132
-
133
- @objc func handleCancel(){
134
-
135
- dismiss(animated: true, completion: nil)
136
-
137
- }
138
-
139
-
140
-
141
- @objc func handleDone(){
142
-
143
- view.endEditing(true)
144
-
145
- dismiss(animated: true, completion: nil)
146
-
147
- }
148
-
149
-
150
-
151
- // MARK: - Helpers
152
-
153
-
154
-
155
- func configureUI(){
156
-
157
- tableView.tableHeaderView = headerView
158
-
159
- headerView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 180)
160
-
161
- headerView.delegate = self
162
-
163
- self.view.addSubview(headerView)
164
-
165
- tableView.register(EditProfileCell.self, forCellReuseIdentifier: reuseIdentifier)
166
-
167
- }
168
-
169
-
170
-
171
- func configureImagePicker(){
172
-
173
- imagePicker.delegate = self
174
-
175
- imagePicker.allowsEditing = true
176
-
177
- }
178
-
179
-
180
-
181
-
182
-
183
- }
184
-
185
-
186
-
187
- extension UITableView {
188
-
189
- open override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
190
-
191
- self.next?.touchesBegan(touches, with: event)
192
-
193
- }
194
-
195
- }
196
-
197
-
198
-
199
- // MARK - UITableViewDataSource
200
-
201
-
202
-
203
- extension EditProfileController {
204
-
205
-
206
-
207
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
208
-
209
- return EditProfileOptions.allCases.count
210
-
211
- }
212
-
213
-
214
-
215
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
216
-
217
- let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as! EditProfileCell
218
-
219
- cell.delegate = self
220
-
221
- guard let option = EditProfileOptions(rawValue: indexPath.row) else { return cell}
222
-
223
- cell.viewModel = EditProfileViewModel(user: user, option: option)
224
-
225
- return cell
226
-
227
- }
228
-
229
-
230
-
231
- // 反応しない
232
-
233
- override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
234
-
235
- self.view.endEditing(true)
236
-
237
-
238
-
239
- }
240
-
241
-
242
-
243
- }
244
-
245
- ```
246
-
247
-
248
-
249
- Headerのコードです。
250
-
251
- ```ここに言語を入力
252
-
253
- import UIKit
254
-
255
- import RealmSwift
256
-
257
-
258
-
259
- protocol EditProfileHeaderDelegate: class {
260
-
261
- func didTapChangeProfilePhoto()
262
-
263
- }
264
-
265
-
266
-
267
- class EditProfileHeader: UIView {
268
-
269
-
270
-
271
- // MARK: - Properties
272
-
273
-
274
-
275
- private let user: Results<User>!
276
-
277
- weak var delegate: EditProfileHeaderDelegate?
278
-
279
-
280
-
281
- let profileImageView: UIImageView = {
282
-
283
- let iv = UIImageView()
284
-
285
- iv.image = UIImage(named: "placeholderImg")
286
-
287
- iv.contentMode = .scaleAspectFill
288
-
289
- iv.clipsToBounds = true
290
-
291
- iv.backgroundColor = .lightGray
292
-
293
- iv.layer.borderColor = UIColor.white.cgColor
294
-
295
- iv.layer.borderWidth = 3.0
296
-
297
- iv.layer.masksToBounds = true
298
-
299
- return iv
300
-
301
- }()
302
-
303
-
304
-
305
- private let changePhotoButton: UIButton = {
306
-
307
- let button = UIButton(type: .system)
308
-
309
- button.setTitle("Change Profile Photo", for: .normal)
310
-
311
- button.addTarget(self, action: #selector(handleChangeProfilePhoto), for: .touchUpInside)
312
-
313
- button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
314
-
315
- button.setTitleColor(.white, for: .normal)
316
-
317
- return button
318
-
319
- }()
320
-
321
-
322
-
323
- // MARK: - Lifecycle
324
-
325
-
326
-
327
- init(user: Results<User>!){
328
-
329
- self.user = user
330
-
331
- super.init(frame: .zero)
332
-
333
-
334
-
335
- isUserInteractionEnabled = true
336
-
337
-
338
-
339
- backgroundColor = .twitterBlue
340
-
341
-
342
-
343
- addSubview(profileImageView)
344
-
345
- profileImageView.center(inView: self, yConstant: -16)
346
-
347
- profileImageView.setDimensions(width: 100, height: 100)
348
-
349
- profileImageView.layer.cornerRadius = 100 / 2
350
-
351
-
352
-
353
- addSubview(changePhotoButton)
354
-
355
- changePhotoButton.centerX(inView: self, topAnchor: profileImageView.bottomAnchor, paddingTop: 8)
356
-
357
- }
358
-
359
-
360
-
361
- required init?(coder: NSCoder) {
362
-
363
- fatalError("init(coder:) has not been implemented")
364
-
365
- }
366
-
367
-
368
-
369
- // MARK: - Selectors
370
-
371
-
372
-
373
- @objc func handleChangeProfilePhoto(){
374
-
375
- delegate?.didTapChangeProfilePhoto()
376
-
377
- }
378
-
379
-
380
-
381
- }
382
-
383
-
384
-
385
- ```