質問編集履歴

3

記入先を変更しました

2020/04/13 14:47

投稿

Eijirou
Eijirou

スコア6

test CHANGED
File without changes
test CHANGED
@@ -1,431 +1,431 @@
1
- ``````ここに言語を入力
1
+ ```import UIKit
2
+
3
+
4
+
5
+ class SettingsViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
6
+
7
+
8
+
9
+
10
+
11
+ @IBOutlet weak var usericonView: UIImageView!
12
+
13
+
14
+
15
+ @IBOutlet weak var nickNameTextField: UITextField!
16
+
17
+
18
+
19
+ @IBOutlet weak var userNameTextField: UITextField!
20
+
21
+
22
+
23
+ @IBOutlet weak var sendEmailTextField: UITextField!
24
+
25
+
26
+
27
+ @IBOutlet weak var sendPhoneNumber: UITextField!
28
+
29
+
30
+
31
+ @IBOutlet weak var nextSendEmailTextField: UITextField!
32
+
33
+
34
+
35
+ @IBOutlet weak var nextSendPhoneNumber: UITextField!
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ @IBOutlet weak var nickNameLabel: UILabel!
44
+
45
+
46
+
47
+ @IBOutlet weak var userNameLabel: UILabel!
48
+
49
+
50
+
51
+ @IBOutlet weak var sendEmailLabel: UILabel!
52
+
53
+
54
+
55
+ @IBOutlet weak var sendPhoneLabel: UILabel!
56
+
57
+
58
+
59
+ @IBOutlet weak var nextSendEmailLabel: UILabel!
60
+
61
+
62
+
63
+ @IBOutlet weak var nextSendPhoneLabel: UILabel!
64
+
65
+
66
+
67
+
68
+
69
+ var nickNameText:String = "ニックネームを入力"
70
+
71
+ var userNameText:String = "名前を入力"
72
+
73
+ var sendEmailText:String = "送り先Emailを入力"
74
+
75
+ var sendPhone:String = "電話番号を入力"
76
+
77
+ var nextSendEmailText:String = "送り先Email-2を入力"
78
+
79
+ var nextSendPhone:String = "電話番号-2を入力"
80
+
81
+
82
+
83
+
84
+
85
+ let userDefaults = UserDefaults.standard
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+ override func viewDidLoad() {
94
+
95
+ super.viewDidLoad()
96
+
97
+
98
+
99
+
100
+
101
+ nickNameTextField.delegate = self
102
+
103
+ userNameTextField.delegate = self
104
+
105
+ sendEmailTextField.delegate = self
106
+
107
+ sendPhoneNumber.delegate = self
108
+
109
+ nextSendEmailTextField.delegate = self
110
+
111
+ nextSendPhoneNumber.delegate = self
112
+
113
+
114
+
115
+ userDefaults.register(defaults: ["NickName": "ニックネームを入力"])
116
+
117
+ nickNameLabel.text = readData()
118
+
119
+
120
+
121
+ userDefaults.register(defaults: ["UserName": "名前を入力"])
122
+
123
+ userNameLabel.text = readData()
124
+
125
+
126
+
127
+ userDefaults.register(defaults: ["SendEmail": "Emailを入力"])
128
+
129
+ sendEmailLabel.text = readData()
130
+
131
+
132
+
133
+ userDefaults.register(defaults: ["SendPhone": "電話番号を入力"])
134
+
135
+ sendPhoneLabel.text = readData()
136
+
137
+
138
+
139
+ userDefaults.register(defaults: ["NextSendEmail": "Emailを入力"])
140
+
141
+ nextSendEmailLabel.text = readData()
142
+
143
+
144
+
145
+ userDefaults.register(defaults: ["NextSendPhone": "電話番号を入力"])
146
+
147
+ nextSendPhoneLabel.text = readData()
148
+
149
+
150
+
151
+ }
152
+
153
+
154
+
155
+ //アルバムの写真を選択してアイコンとして表示する。
156
+
157
+ @IBAction func toAlbumButton(_ sender: Any) {
158
+
159
+
160
+
161
+ let picker = UIImagePickerController()
162
+
163
+ picker.sourceType = .photoLibrary
164
+
165
+ picker.delegate = self
166
+
167
+ present(picker, animated: true)
168
+
169
+ self.present(picker, animated: true, completion: nil)
170
+
171
+
172
+
173
+ }
174
+
175
+
176
+
177
+ func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
178
+
179
+ if let selectedImage = info[.originalImage] as? UIImage{
180
+
181
+ usericonView.image = selectedImage
182
+
183
+ }
184
+
185
+ self.dismiss(animated: true)
186
+
187
+ }
188
+
189
+
190
+
191
+ func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
192
+
193
+ self.dismiss(animated: true, completion: nil)
194
+
195
+ }
196
+
197
+
198
+
199
+ //テキスト入力設定
200
+
201
+
202
+
203
+ func textFieldShouldReturn(_ textField: UITextField) -> Bool{
204
+
205
+ nickNameText = textField.text!
206
+
207
+ nickNameLabel.text = nickNameText
208
+
209
+
210
+
211
+ userNameText = textField.text!
212
+
213
+ userNameLabel.text = userNameText
214
+
215
+
216
+
217
+ sendEmailText = textField.text!
218
+
219
+ sendEmailLabel.text = sendEmailText
220
+
221
+
222
+
223
+ sendPhone = textField.text!
224
+
225
+ sendPhoneLabel.text = sendPhone
226
+
227
+
228
+
229
+ nextSendEmailText = textField.text!
230
+
231
+ nextSendEmailLabel.text = nextSendEmailText
232
+
233
+
234
+
235
+ nextSendPhone = textField.text!
236
+
237
+ nextSendPhoneLabel.text = nextSendPhone
238
+
239
+
240
+
241
+
242
+
243
+ textField.resignFirstResponder()
244
+
245
+
246
+
247
+ saveData(str: nickNameText)
248
+
249
+ saveData(str: userNameText)
250
+
251
+ saveData(str: sendEmailText)
252
+
253
+ saveData(str: sendPhone)
254
+
255
+ saveData(str: nextSendEmailText)
256
+
257
+ saveData(str: nextSendPhone)
258
+
259
+
260
+
261
+ return true
262
+
263
+
264
+
265
+ }
266
+
267
+
268
+
269
+ func saveData(str: String){
270
+
271
+ userDefaults.set(str, forKey: "NickName")
272
+
273
+ userDefaults.set(str, forKey: "UserName")
274
+
275
+ userDefaults.set(str, forKey: "SendEmail")
276
+
277
+ userDefaults.set(str, forKey: "SendPhone")
278
+
279
+ userDefaults.set(str, forKey: "NextSendEmail")
280
+
281
+ userDefaults.set(str, forKey: "NextSendPhone")
282
+
283
+ }
284
+
285
+
286
+
287
+ func readData() -> String {
288
+
289
+ let str: String = userDefaults.object(forKey: "NickName") as! String
290
+
291
+
292
+
293
+ let _: String = userDefaults.object(forKey: "UserName") as! String
294
+
295
+
296
+
297
+ let _: String = userDefaults.object(forKey: "SendEmail") as! String
298
+
299
+
300
+
301
+ let _: String = userDefaults.object(forKey: "SendPhone") as! String
302
+
303
+
304
+
305
+ let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
306
+
307
+
308
+
309
+ let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
310
+
311
+
312
+
313
+ return str
314
+
315
+
316
+
317
+ }
318
+
319
+
320
+
321
+
322
+
323
+ @IBAction func hozonButtton(_ sender : AnyObject) {
324
+
325
+
326
+
327
+ // Key の値を削除
328
+
329
+ userDefaults.removeObject(forKey: "NickName")
330
+
331
+ userDefaults.removeObject(forKey: "UserName")
332
+
333
+ userDefaults.removeObject(forKey: "SendEmail")
334
+
335
+ userDefaults.removeObject(forKey: "SendPhone")
336
+
337
+ userDefaults.removeObject(forKey: "NextsendEmail")
338
+
339
+ userDefaults.removeObject(forKey: "NextSendPhone")
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+ userDefaults.set(true, forKey: "NickName")
348
+
349
+ let str: String = userDefaults.object(forKey: "NickName") as! String
350
+
351
+ nickNameLabel.text = str
352
+
353
+
354
+
355
+ userDefaults.set(true, forKey: "UserName")
356
+
357
+ let _: String = userDefaults.object(forKey: "UserName") as! String
358
+
359
+ nickNameLabel.text = str
360
+
361
+
362
+
363
+ userDefaults.set(true, forKey: "SendEmail")
364
+
365
+ let _: String = userDefaults.object(forKey: "SendEmail") as! String
366
+
367
+ nickNameLabel.text = str
368
+
369
+
370
+
371
+ userDefaults.set(true, forKey: "SendPhone")
372
+
373
+ let _: String = userDefaults.object(forKey: "SendPhone") as! String
374
+
375
+ nickNameLabel.text = str
376
+
377
+
378
+
379
+ userDefaults.set(true, forKey: "NextSendemail")
380
+
381
+ let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
382
+
383
+ nickNameLabel.text = str
384
+
385
+
386
+
387
+ userDefaults.set(true, forKey: "NextSendPhone")
388
+
389
+ let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
390
+
391
+ nickNameLabel.text = str
392
+
393
+
394
+
395
+ nickNameLabel.text = str
396
+
397
+ userNameLabel.text = str
398
+
399
+ sendEmailLabel.text = str
400
+
401
+ sendPhoneLabel.text = str
402
+
403
+ nextSendEmailLabel.text = str
404
+
405
+ nextSendPhoneLabel.text = str
406
+
407
+
408
+
409
+
410
+
411
+ print()
412
+
413
+
414
+
415
+ }
416
+
417
+
418
+
419
+
420
+
421
+ }
422
+
423
+
2
424
 
3
425
  コード
4
426
 
5
427
  ```
6
428
 
7
- import UIKit
8
-
9
-
10
-
11
- class SettingsViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
12
-
13
-
14
-
15
-
16
-
17
- @IBOutlet weak var usericonView: UIImageView!
18
-
19
-
20
-
21
- @IBOutlet weak var nickNameTextField: UITextField!
22
-
23
-
24
-
25
- @IBOutlet weak var userNameTextField: UITextField!
26
-
27
-
28
-
29
- @IBOutlet weak var sendEmailTextField: UITextField!
30
-
31
-
32
-
33
- @IBOutlet weak var sendPhoneNumber: UITextField!
34
-
35
-
36
-
37
- @IBOutlet weak var nextSendEmailTextField: UITextField!
38
-
39
-
40
-
41
- @IBOutlet weak var nextSendPhoneNumber: UITextField!
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
- @IBOutlet weak var nickNameLabel: UILabel!
50
-
51
-
52
-
53
- @IBOutlet weak var userNameLabel: UILabel!
54
-
55
-
56
-
57
- @IBOutlet weak var sendEmailLabel: UILabel!
58
-
59
-
60
-
61
- @IBOutlet weak var sendPhoneLabel: UILabel!
62
-
63
-
64
-
65
- @IBOutlet weak var nextSendEmailLabel: UILabel!
66
-
67
-
68
-
69
- @IBOutlet weak var nextSendPhoneLabel: UILabel!
70
-
71
-
72
-
73
-
74
-
75
- var nickNameText:String = "ニックネームを入力"
76
-
77
- var userNameText:String = "名前を入力"
78
-
79
- var sendEmailText:String = "送り先Emailを入力"
80
-
81
- var sendPhone:String = "電話番号を入力"
82
-
83
- var nextSendEmailText:String = "送り先Email-2を入力"
84
-
85
- var nextSendPhone:String = "電話番号-2を入力"
86
-
87
-
88
-
89
-
90
-
91
- let userDefaults = UserDefaults.standard
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
- override func viewDidLoad() {
100
-
101
- super.viewDidLoad()
102
-
103
-
104
-
105
-
106
-
107
- nickNameTextField.delegate = self
108
-
109
- userNameTextField.delegate = self
110
-
111
- sendEmailTextField.delegate = self
112
-
113
- sendPhoneNumber.delegate = self
114
-
115
- nextSendEmailTextField.delegate = self
116
-
117
- nextSendPhoneNumber.delegate = self
118
-
119
-
120
-
121
- userDefaults.register(defaults: ["NickName": "ニックネームを入力"])
122
-
123
- nickNameLabel.text = readData()
124
-
125
-
126
-
127
- userDefaults.register(defaults: ["UserName": "名前を入力"])
128
-
129
- userNameLabel.text = readData()
130
-
131
-
132
-
133
- userDefaults.register(defaults: ["SendEmail": "Emailを入力"])
134
-
135
- sendEmailLabel.text = readData()
136
-
137
-
138
-
139
- userDefaults.register(defaults: ["SendPhone": "電話番号を入力"])
140
-
141
- sendPhoneLabel.text = readData()
142
-
143
-
144
-
145
- userDefaults.register(defaults: ["NextSendEmail": "Emailを入力"])
146
-
147
- nextSendEmailLabel.text = readData()
148
-
149
-
150
-
151
- userDefaults.register(defaults: ["NextSendPhone": "電話番号を入力"])
152
-
153
- nextSendPhoneLabel.text = readData()
154
-
155
-
156
-
157
- }
158
-
159
-
160
-
161
- //アルバムの写真を選択してアイコンとして表示する。
162
-
163
- @IBAction func toAlbumButton(_ sender: Any) {
164
-
165
-
166
-
167
- let picker = UIImagePickerController()
168
-
169
- picker.sourceType = .photoLibrary
170
-
171
- picker.delegate = self
172
-
173
- present(picker, animated: true)
174
-
175
- self.present(picker, animated: true, completion: nil)
176
-
177
-
178
-
179
- }
180
-
181
-
182
-
183
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
184
-
185
- if let selectedImage = info[.originalImage] as? UIImage{
186
-
187
- usericonView.image = selectedImage
188
-
189
- }
190
-
191
- self.dismiss(animated: true)
192
-
193
- }
194
-
195
-
196
-
197
- func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
198
-
199
- self.dismiss(animated: true, completion: nil)
200
-
201
- }
202
-
203
-
204
-
205
- //テキスト入力設定
206
-
207
-
208
-
209
- func textFieldShouldReturn(_ textField: UITextField) -> Bool{
210
-
211
- nickNameText = textField.text!
212
-
213
- nickNameLabel.text = nickNameText
214
-
215
-
216
-
217
- userNameText = textField.text!
218
-
219
- userNameLabel.text = userNameText
220
-
221
-
222
-
223
- sendEmailText = textField.text!
224
-
225
- sendEmailLabel.text = sendEmailText
226
-
227
-
228
-
229
- sendPhone = textField.text!
230
-
231
- sendPhoneLabel.text = sendPhone
232
-
233
-
234
-
235
- nextSendEmailText = textField.text!
236
-
237
- nextSendEmailLabel.text = nextSendEmailText
238
-
239
-
240
-
241
- nextSendPhone = textField.text!
242
-
243
- nextSendPhoneLabel.text = nextSendPhone
244
-
245
-
246
-
247
-
248
-
249
- textField.resignFirstResponder()
250
-
251
-
252
-
253
- saveData(str: nickNameText)
254
-
255
- saveData(str: userNameText)
256
-
257
- saveData(str: sendEmailText)
258
-
259
- saveData(str: sendPhone)
260
-
261
- saveData(str: nextSendEmailText)
262
-
263
- saveData(str: nextSendPhone)
264
-
265
-
266
-
267
- return true
268
-
269
-
270
-
271
- }
272
-
273
-
274
-
275
- func saveData(str: String){
276
-
277
- userDefaults.set(str, forKey: "NickName")
278
-
279
- userDefaults.set(str, forKey: "UserName")
280
-
281
- userDefaults.set(str, forKey: "SendEmail")
282
-
283
- userDefaults.set(str, forKey: "SendPhone")
284
-
285
- userDefaults.set(str, forKey: "NextSendEmail")
286
-
287
- userDefaults.set(str, forKey: "NextSendPhone")
288
-
289
- }
290
-
291
-
292
-
293
- func readData() -> String {
294
-
295
- let str: String = userDefaults.object(forKey: "NickName") as! String
296
-
297
-
298
-
299
- let _: String = userDefaults.object(forKey: "UserName") as! String
300
-
301
-
302
-
303
- let _: String = userDefaults.object(forKey: "SendEmail") as! String
304
-
305
-
306
-
307
- let _: String = userDefaults.object(forKey: "SendPhone") as! String
308
-
309
-
310
-
311
- let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
312
-
313
-
314
-
315
- let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
316
-
317
-
318
-
319
- return str
320
-
321
-
322
-
323
- }
324
-
325
-
326
-
327
-
328
-
329
- @IBAction func hozonButtton(_ sender : AnyObject) {
330
-
331
-
332
-
333
- // Key の値を削除
334
-
335
- userDefaults.removeObject(forKey: "NickName")
336
-
337
- userDefaults.removeObject(forKey: "UserName")
338
-
339
- userDefaults.removeObject(forKey: "SendEmail")
340
-
341
- userDefaults.removeObject(forKey: "SendPhone")
342
-
343
- userDefaults.removeObject(forKey: "NextsendEmail")
344
-
345
- userDefaults.removeObject(forKey: "NextSendPhone")
346
-
347
-
348
-
349
-
350
-
351
-
352
-
353
- userDefaults.set(true, forKey: "NickName")
354
-
355
- let str: String = userDefaults.object(forKey: "NickName") as! String
356
-
357
- nickNameLabel.text = str
358
-
359
-
360
-
361
- userDefaults.set(true, forKey: "UserName")
362
-
363
- let _: String = userDefaults.object(forKey: "UserName") as! String
364
-
365
- nickNameLabel.text = str
366
-
367
-
368
-
369
- userDefaults.set(true, forKey: "SendEmail")
370
-
371
- let _: String = userDefaults.object(forKey: "SendEmail") as! String
372
-
373
- nickNameLabel.text = str
374
-
375
-
376
-
377
- userDefaults.set(true, forKey: "SendPhone")
378
-
379
- let _: String = userDefaults.object(forKey: "SendPhone") as! String
380
-
381
- nickNameLabel.text = str
382
-
383
-
384
-
385
- userDefaults.set(true, forKey: "NextSendemail")
386
-
387
- let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
388
-
389
- nickNameLabel.text = str
390
-
391
-
392
-
393
- userDefaults.set(true, forKey: "NextSendPhone")
394
-
395
- let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
396
-
397
- nickNameLabel.text = str
398
-
399
-
400
-
401
- nickNameLabel.text = str
402
-
403
- userNameLabel.text = str
404
-
405
- sendEmailLabel.text = str
406
-
407
- sendPhoneLabel.text = str
408
-
409
- nextSendEmailLabel.text = str
410
-
411
- nextSendPhoneLabel.text = str
412
-
413
-
414
-
415
-
416
-
417
- print()
418
-
419
-
420
-
421
- }
422
-
423
-
424
-
425
-
426
-
427
- }
428
-
429
429
 
430
430
 
431
431
  ```設定画面でtextFieldの値をTextLabelに表示して保存するコードを書いてます。

2

記入先を変更しました

2020/04/13 14:47

投稿

Eijirou
Eijirou

スコア6

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,434 @@
1
+ ``````ここに言語を入力
2
+
3
+ コード
4
+
5
+ ```
6
+
7
+ import UIKit
8
+
9
+
10
+
11
+ class SettingsViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
12
+
13
+
14
+
15
+
16
+
17
+ @IBOutlet weak var usericonView: UIImageView!
18
+
19
+
20
+
21
+ @IBOutlet weak var nickNameTextField: UITextField!
22
+
23
+
24
+
25
+ @IBOutlet weak var userNameTextField: UITextField!
26
+
27
+
28
+
29
+ @IBOutlet weak var sendEmailTextField: UITextField!
30
+
31
+
32
+
33
+ @IBOutlet weak var sendPhoneNumber: UITextField!
34
+
35
+
36
+
37
+ @IBOutlet weak var nextSendEmailTextField: UITextField!
38
+
39
+
40
+
41
+ @IBOutlet weak var nextSendPhoneNumber: UITextField!
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+ @IBOutlet weak var nickNameLabel: UILabel!
50
+
51
+
52
+
53
+ @IBOutlet weak var userNameLabel: UILabel!
54
+
55
+
56
+
57
+ @IBOutlet weak var sendEmailLabel: UILabel!
58
+
59
+
60
+
61
+ @IBOutlet weak var sendPhoneLabel: UILabel!
62
+
63
+
64
+
65
+ @IBOutlet weak var nextSendEmailLabel: UILabel!
66
+
67
+
68
+
69
+ @IBOutlet weak var nextSendPhoneLabel: UILabel!
70
+
71
+
72
+
73
+
74
+
75
+ var nickNameText:String = "ニックネームを入力"
76
+
77
+ var userNameText:String = "名前を入力"
78
+
79
+ var sendEmailText:String = "送り先Emailを入力"
80
+
81
+ var sendPhone:String = "電話番号を入力"
82
+
83
+ var nextSendEmailText:String = "送り先Email-2を入力"
84
+
85
+ var nextSendPhone:String = "電話番号-2を入力"
86
+
87
+
88
+
89
+
90
+
91
+ let userDefaults = UserDefaults.standard
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+ override func viewDidLoad() {
100
+
101
+ super.viewDidLoad()
102
+
103
+
104
+
105
+
106
+
107
+ nickNameTextField.delegate = self
108
+
109
+ userNameTextField.delegate = self
110
+
111
+ sendEmailTextField.delegate = self
112
+
113
+ sendPhoneNumber.delegate = self
114
+
115
+ nextSendEmailTextField.delegate = self
116
+
117
+ nextSendPhoneNumber.delegate = self
118
+
119
+
120
+
121
+ userDefaults.register(defaults: ["NickName": "ニックネームを入力"])
122
+
123
+ nickNameLabel.text = readData()
124
+
125
+
126
+
127
+ userDefaults.register(defaults: ["UserName": "名前を入力"])
128
+
129
+ userNameLabel.text = readData()
130
+
131
+
132
+
133
+ userDefaults.register(defaults: ["SendEmail": "Emailを入力"])
134
+
135
+ sendEmailLabel.text = readData()
136
+
137
+
138
+
139
+ userDefaults.register(defaults: ["SendPhone": "電話番号を入力"])
140
+
141
+ sendPhoneLabel.text = readData()
142
+
143
+
144
+
145
+ userDefaults.register(defaults: ["NextSendEmail": "Emailを入力"])
146
+
147
+ nextSendEmailLabel.text = readData()
148
+
149
+
150
+
151
+ userDefaults.register(defaults: ["NextSendPhone": "電話番号を入力"])
152
+
153
+ nextSendPhoneLabel.text = readData()
154
+
155
+
156
+
157
+ }
158
+
159
+
160
+
161
+ //アルバムの写真を選択してアイコンとして表示する。
162
+
163
+ @IBAction func toAlbumButton(_ sender: Any) {
164
+
165
+
166
+
167
+ let picker = UIImagePickerController()
168
+
169
+ picker.sourceType = .photoLibrary
170
+
171
+ picker.delegate = self
172
+
173
+ present(picker, animated: true)
174
+
175
+ self.present(picker, animated: true, completion: nil)
176
+
177
+
178
+
179
+ }
180
+
181
+
182
+
183
+ func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
184
+
185
+ if let selectedImage = info[.originalImage] as? UIImage{
186
+
187
+ usericonView.image = selectedImage
188
+
189
+ }
190
+
191
+ self.dismiss(animated: true)
192
+
193
+ }
194
+
195
+
196
+
197
+ func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
198
+
199
+ self.dismiss(animated: true, completion: nil)
200
+
201
+ }
202
+
203
+
204
+
205
+ //テキスト入力設定
206
+
207
+
208
+
209
+ func textFieldShouldReturn(_ textField: UITextField) -> Bool{
210
+
211
+ nickNameText = textField.text!
212
+
213
+ nickNameLabel.text = nickNameText
214
+
215
+
216
+
217
+ userNameText = textField.text!
218
+
219
+ userNameLabel.text = userNameText
220
+
221
+
222
+
223
+ sendEmailText = textField.text!
224
+
225
+ sendEmailLabel.text = sendEmailText
226
+
227
+
228
+
229
+ sendPhone = textField.text!
230
+
231
+ sendPhoneLabel.text = sendPhone
232
+
233
+
234
+
235
+ nextSendEmailText = textField.text!
236
+
237
+ nextSendEmailLabel.text = nextSendEmailText
238
+
239
+
240
+
241
+ nextSendPhone = textField.text!
242
+
243
+ nextSendPhoneLabel.text = nextSendPhone
244
+
245
+
246
+
247
+
248
+
249
+ textField.resignFirstResponder()
250
+
251
+
252
+
253
+ saveData(str: nickNameText)
254
+
255
+ saveData(str: userNameText)
256
+
257
+ saveData(str: sendEmailText)
258
+
259
+ saveData(str: sendPhone)
260
+
261
+ saveData(str: nextSendEmailText)
262
+
263
+ saveData(str: nextSendPhone)
264
+
265
+
266
+
267
+ return true
268
+
269
+
270
+
271
+ }
272
+
273
+
274
+
275
+ func saveData(str: String){
276
+
277
+ userDefaults.set(str, forKey: "NickName")
278
+
279
+ userDefaults.set(str, forKey: "UserName")
280
+
281
+ userDefaults.set(str, forKey: "SendEmail")
282
+
283
+ userDefaults.set(str, forKey: "SendPhone")
284
+
285
+ userDefaults.set(str, forKey: "NextSendEmail")
286
+
287
+ userDefaults.set(str, forKey: "NextSendPhone")
288
+
289
+ }
290
+
291
+
292
+
293
+ func readData() -> String {
294
+
295
+ let str: String = userDefaults.object(forKey: "NickName") as! String
296
+
297
+
298
+
299
+ let _: String = userDefaults.object(forKey: "UserName") as! String
300
+
301
+
302
+
303
+ let _: String = userDefaults.object(forKey: "SendEmail") as! String
304
+
305
+
306
+
307
+ let _: String = userDefaults.object(forKey: "SendPhone") as! String
308
+
309
+
310
+
311
+ let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
312
+
313
+
314
+
315
+ let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
316
+
317
+
318
+
319
+ return str
320
+
321
+
322
+
323
+ }
324
+
325
+
326
+
327
+
328
+
329
+ @IBAction func hozonButtton(_ sender : AnyObject) {
330
+
331
+
332
+
333
+ // Key の値を削除
334
+
335
+ userDefaults.removeObject(forKey: "NickName")
336
+
337
+ userDefaults.removeObject(forKey: "UserName")
338
+
339
+ userDefaults.removeObject(forKey: "SendEmail")
340
+
341
+ userDefaults.removeObject(forKey: "SendPhone")
342
+
343
+ userDefaults.removeObject(forKey: "NextsendEmail")
344
+
345
+ userDefaults.removeObject(forKey: "NextSendPhone")
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+ userDefaults.set(true, forKey: "NickName")
354
+
355
+ let str: String = userDefaults.object(forKey: "NickName") as! String
356
+
357
+ nickNameLabel.text = str
358
+
359
+
360
+
361
+ userDefaults.set(true, forKey: "UserName")
362
+
363
+ let _: String = userDefaults.object(forKey: "UserName") as! String
364
+
365
+ nickNameLabel.text = str
366
+
367
+
368
+
369
+ userDefaults.set(true, forKey: "SendEmail")
370
+
371
+ let _: String = userDefaults.object(forKey: "SendEmail") as! String
372
+
373
+ nickNameLabel.text = str
374
+
375
+
376
+
377
+ userDefaults.set(true, forKey: "SendPhone")
378
+
379
+ let _: String = userDefaults.object(forKey: "SendPhone") as! String
380
+
381
+ nickNameLabel.text = str
382
+
383
+
384
+
385
+ userDefaults.set(true, forKey: "NextSendemail")
386
+
387
+ let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
388
+
389
+ nickNameLabel.text = str
390
+
391
+
392
+
393
+ userDefaults.set(true, forKey: "NextSendPhone")
394
+
395
+ let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
396
+
397
+ nickNameLabel.text = str
398
+
399
+
400
+
401
+ nickNameLabel.text = str
402
+
403
+ userNameLabel.text = str
404
+
405
+ sendEmailLabel.text = str
406
+
407
+ sendPhoneLabel.text = str
408
+
409
+ nextSendEmailLabel.text = str
410
+
411
+ nextSendPhoneLabel.text = str
412
+
413
+
414
+
415
+
416
+
417
+ print()
418
+
419
+
420
+
421
+ }
422
+
423
+
424
+
425
+
426
+
427
+ }
428
+
429
+
430
+
1
- 設定画面でtextFieldの値をTextLabelに表示して保存するコードを書いてます。
431
+ ```設定画面でtextFieldの値をTextLabelに表示して保存するコードを書いてます。
2
432
 
3
433
 
4
434
 

1

リスト表示を追加

2020/04/13 14:46

投稿

Eijirou
Eijirou

スコア6

test CHANGED
File without changes
test CHANGED
@@ -34,428 +34,6 @@
34
34
 
35
35
 
36
36
 
37
- import UIKit
38
-
39
-
40
-
41
- class SettingsViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate {
42
-
43
-
44
-
45
-
46
-
47
- @IBOutlet weak var usericonView: UIImageView!
48
-
49
-
50
-
51
- @IBOutlet weak var nickNameTextField: UITextField!
52
-
53
-
54
-
55
- @IBOutlet weak var userNameTextField: UITextField!
56
-
57
-
58
-
59
- @IBOutlet weak var sendEmailTextField: UITextField!
60
-
61
-
62
-
63
- @IBOutlet weak var sendPhoneNumber: UITextField!
64
-
65
-
66
-
67
- @IBOutlet weak var nextSendEmailTextField: UITextField!
68
-
69
-
70
-
71
- @IBOutlet weak var nextSendPhoneNumber: UITextField!
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
- @IBOutlet weak var nickNameLabel: UILabel!
80
-
81
-
82
-
83
- @IBOutlet weak var userNameLabel: UILabel!
84
-
85
-
86
-
87
- @IBOutlet weak var sendEmailLabel: UILabel!
88
-
89
-
90
-
91
- @IBOutlet weak var sendPhoneLabel: UILabel!
92
-
93
-
94
-
95
- @IBOutlet weak var nextSendEmailLabel: UILabel!
96
-
97
-
98
-
99
- @IBOutlet weak var nextSendPhoneLabel: UILabel!
100
-
101
-
102
-
103
-
104
-
105
- var nickNameText:String = "ニックネームを入力"
106
-
107
- var userNameText:String = "名前を入力"
108
-
109
- var sendEmailText:String = "送り先Emailを入力"
110
-
111
- var sendPhone:String = "電話番号を入力"
112
-
113
- var nextSendEmailText:String = "送り先Email-2を入力"
114
-
115
- var nextSendPhone:String = "電話番号-2を入力"
116
-
117
-
118
-
119
-
120
-
121
- let userDefaults = UserDefaults.standard
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
- override func viewDidLoad() {
130
-
131
- super.viewDidLoad()
132
-
133
-
134
-
135
-
136
-
137
- nickNameTextField.delegate = self
138
-
139
- userNameTextField.delegate = self
140
-
141
- sendEmailTextField.delegate = self
142
-
143
- sendPhoneNumber.delegate = self
144
-
145
- nextSendEmailTextField.delegate = self
146
-
147
- nextSendPhoneNumber.delegate = self
148
-
149
-
150
-
151
- userDefaults.register(defaults: ["NickName": "ニックネームを入力"])
152
-
153
- nickNameLabel.text = readData()
154
-
155
-
156
-
157
- userDefaults.register(defaults: ["UserName": "名前を入力"])
158
-
159
- userNameLabel.text = readData()
160
-
161
-
162
-
163
- userDefaults.register(defaults: ["SendEmail": "Emailを入力"])
164
-
165
- sendEmailLabel.text = readData()
166
-
167
-
168
-
169
- userDefaults.register(defaults: ["SendPhone": "電話番号を入力"])
170
-
171
- sendPhoneLabel.text = readData()
172
-
173
-
174
-
175
- userDefaults.register(defaults: ["NextSendEmail": "Emailを入力"])
176
-
177
- nextSendEmailLabel.text = readData()
178
-
179
-
180
-
181
- userDefaults.register(defaults: ["NextSendPhone": "電話番号を入力"])
182
-
183
- nextSendPhoneLabel.text = readData()
184
-
185
-
186
-
187
- }
188
-
189
-
190
-
191
- //アルバムの写真を選択してアイコンとして表示する。
192
-
193
- @IBAction func toAlbumButton(_ sender: Any) {
194
-
195
-
196
-
197
- let picker = UIImagePickerController()
198
-
199
- picker.sourceType = .photoLibrary
200
-
201
- picker.delegate = self
202
-
203
- present(picker, animated: true)
204
-
205
- self.present(picker, animated: true, completion: nil)
206
-
207
-
208
-
209
- }
210
-
211
-
212
-
213
- func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
214
-
215
- if let selectedImage = info[.originalImage] as? UIImage{
216
-
217
- usericonView.image = selectedImage
218
-
219
- }
220
-
221
- self.dismiss(animated: true)
222
-
223
- }
224
-
225
-
226
-
227
- func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
228
-
229
- self.dismiss(animated: true, completion: nil)
230
-
231
- }
232
-
233
-
234
-
235
- //テキスト入力設定
236
-
237
-
238
-
239
- func textFieldShouldReturn(_ textField: UITextField) -> Bool{
240
-
241
- nickNameText = textField.text!
242
-
243
- nickNameLabel.text = nickNameText
244
-
245
-
246
-
247
- userNameText = textField.text!
248
-
249
- userNameLabel.text = userNameText
250
-
251
-
252
-
253
- sendEmailText = textField.text!
254
-
255
- sendEmailLabel.text = sendEmailText
256
-
257
-
258
-
259
- sendPhone = textField.text!
260
-
261
- sendPhoneLabel.text = sendPhone
262
-
263
-
264
-
265
- nextSendEmailText = textField.text!
266
-
267
- nextSendEmailLabel.text = nextSendEmailText
268
-
269
-
270
-
271
- nextSendPhone = textField.text!
272
-
273
- nextSendPhoneLabel.text = nextSendPhone
274
-
275
-
276
-
277
-
278
-
279
- textField.resignFirstResponder()
280
-
281
-
282
-
283
- saveData(str: nickNameText)
284
-
285
- saveData(str: userNameText)
286
-
287
- saveData(str: sendEmailText)
288
-
289
- saveData(str: sendPhone)
290
-
291
- saveData(str: nextSendEmailText)
292
-
293
- saveData(str: nextSendPhone)
294
-
295
-
296
-
297
- return true
298
-
299
-
300
-
301
- }
302
-
303
-
304
-
305
- func saveData(str: String){
306
-
307
- userDefaults.set(str, forKey: "NickName")
308
-
309
- userDefaults.set(str, forKey: "UserName")
310
-
311
- userDefaults.set(str, forKey: "SendEmail")
312
-
313
- userDefaults.set(str, forKey: "SendPhone")
314
-
315
- userDefaults.set(str, forKey: "NextSendEmail")
316
-
317
- userDefaults.set(str, forKey: "NextSendPhone")
318
-
319
- }
320
-
321
-
322
-
323
- func readData() -> String {
324
-
325
- let str: String = userDefaults.object(forKey: "NickName") as! String
326
-
327
-
328
-
329
- let _: String = userDefaults.object(forKey: "UserName") as! String
330
-
331
-
332
-
333
- let _: String = userDefaults.object(forKey: "SendEmail") as! String
334
-
335
-
336
-
337
- let _: String = userDefaults.object(forKey: "SendPhone") as! String
338
-
339
-
340
-
341
- let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
342
-
343
-
344
-
345
- let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
346
-
347
-
348
-
349
- return str
350
-
351
-
352
-
353
- }
354
-
355
-
356
-
357
-
358
-
359
- @IBAction func hozonButtton(_ sender : AnyObject) {
360
-
361
-
362
-
363
- // Key の値を削除
364
-
365
- userDefaults.removeObject(forKey: "NickName")
366
-
367
- userDefaults.removeObject(forKey: "UserName")
368
-
369
- userDefaults.removeObject(forKey: "SendEmail")
370
-
371
- userDefaults.removeObject(forKey: "SendPhone")
372
-
373
- userDefaults.removeObject(forKey: "NextsendEmail")
374
-
375
- userDefaults.removeObject(forKey: "NextSendPhone")
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
- userDefaults.set(true, forKey: "NickName")
384
-
385
- let str: String = userDefaults.object(forKey: "NickName") as! String
386
-
387
- nickNameLabel.text = str
388
-
389
-
390
-
391
- userDefaults.set(true, forKey: "UserName")
392
-
393
- let _: String = userDefaults.object(forKey: "UserName") as! String
394
-
395
- nickNameLabel.text = str
396
-
397
-
398
-
399
- userDefaults.set(true, forKey: "SendEmail")
400
-
401
- let _: String = userDefaults.object(forKey: "SendEmail") as! String
402
-
403
- nickNameLabel.text = str
404
-
405
-
406
-
407
- userDefaults.set(true, forKey: "SendPhone")
408
-
409
- let _: String = userDefaults.object(forKey: "SendPhone") as! String
410
-
411
- nickNameLabel.text = str
412
-
413
-
414
-
415
- userDefaults.set(true, forKey: "NextSendemail")
416
-
417
- let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
418
-
419
- nickNameLabel.text = str
420
-
421
-
422
-
423
- userDefaults.set(true, forKey: "NextSendPhone")
424
-
425
- let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
426
-
427
- nickNameLabel.text = str
428
-
429
-
430
-
431
- nickNameLabel.text = str
432
-
433
- userNameLabel.text = str
434
-
435
- sendEmailLabel.text = str
436
-
437
- sendPhoneLabel.text = str
438
-
439
- nextSendEmailLabel.text = str
440
-
441
- nextSendPhoneLabel.text = str
442
-
443
-
444
-
445
-
446
-
447
- print()
448
-
449
-
450
-
451
- }
452
-
453
-
454
-
455
-
456
-
457
- }
458
-
459
37
 
460
38
 
461
39