質問編集履歴

5

hread 1: Exception: "は自己解決。残りの問題の表題を変更。

2020/04/14 16:45

投稿

Eijirou
Eijirou

スコア6

test CHANGED
@@ -1 +1 @@
1
- hread 1: Exception: "-[KidsSosApp.SettingsViewController hozonButton:]: unrecognized selector sent t
1
+ textFieldの値が全てのtextLabelに入ってしう問題を解決したいです。
test CHANGED
File without changes

4

テンプレートを編集しました。

2020/04/14 16:45

投稿

Eijirou
Eijirou

スコア6

test CHANGED
File without changes
test CHANGED
@@ -455,3 +455,57 @@
455
455
  hread 1: Exception: "-[KidsSosApp.SettingsViewController hozonButton:]: unrecognized selector sent to instance 0x7ff6a3832600"
456
456
 
457
457
  です。
458
+
459
+ ### 前提・実現したいこと
460
+
461
+
462
+
463
+ ここに質問の内容を詳しく書いてください。
464
+
465
+ textfieldに入れた値をtextLabelに表示させて保存する。というのを作成中です。
466
+
467
+ それぞれのtextFieldの値をtextLabelに入れたいのに最後に入れた値が全てのtextLabelに
468
+
469
+ はいってしまします。
470
+
471
+ また、保存ボタンを押すと表題のエラーコードが発生しました。
472
+
473
+
474
+
475
+ ### 発生している問題・エラーメッセージ
476
+
477
+
478
+
479
+ ```
480
+
481
+ hread 1: Exception: "-[KidsSosApp.SettingsViewController hozonButton:]: unrecognized selector sent t
482
+
483
+ ```
484
+
485
+
486
+
487
+ ### 該当のソースコード
488
+
489
+
490
+
491
+ ```ここに言語名を入力
492
+
493
+ ソースコード
494
+
495
+ ```
496
+
497
+
498
+
499
+ ### 試したこと
500
+
501
+
502
+
503
+ ここに問題に対して試したことを記載してください。
504
+
505
+
506
+
507
+ ### 補足情報(FW/ツールのバージョンなど)
508
+
509
+
510
+
511
+ ここにより詳細な情報を記載してください。

3

エラーを起こしているコードを添付

2020/04/14 01:04

投稿

Eijirou
Eijirou

スコア6

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,392 @@
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
+
102
+
103
+ nickNameTextField.delegate = self
104
+
105
+ userNameTextField.delegate = self
106
+
107
+ sendEmailTextField.delegate = self
108
+
109
+ sendPhoneNumber.delegate = self
110
+
111
+ nextSendEmailTextField.delegate = self
112
+
113
+ nextSendPhoneNumber.delegate = self
114
+
115
+
116
+
117
+ userDefaults.register(defaults: ["NickName": "ニックネームを入力"])
118
+
119
+ nickNameLabel.text = readData(key: "NickName")
120
+
121
+
122
+
123
+ userDefaults.register(defaults: ["UserName": "名前を入力"])
124
+
125
+ userNameLabel.text = readData(key: "UserName")
126
+
127
+
128
+
129
+ userDefaults.register(defaults: ["SendEmail": "Emailを入力"])
130
+
131
+ sendEmailLabel.text = readData(key: "SendEmail")
132
+
133
+
134
+
135
+ userDefaults.register(defaults: ["SendPhone": "電話番号を入力"])
136
+
137
+ sendPhoneLabel.text = readData(key: "SendPhone")
138
+
139
+
140
+
141
+ userDefaults.register(defaults: ["NextSendEmail": "Emailを入力"])
142
+
143
+ nextSendEmailLabel.text = readData(key: "nextSendEmail")
144
+
145
+
146
+
147
+ userDefaults.register(defaults: ["NextSendPhone": "電話番号を入力"])
148
+
149
+ nextSendPhoneLabel.text = readData(key: "NextSendPhone")
150
+
151
+
152
+
153
+ }
154
+
155
+
156
+
157
+ //アルバムの写真を選択してアイコンとして表示する。
158
+
159
+ @IBAction func toAlbumButton(_ sender: Any) {
160
+
161
+
162
+
163
+ let picker = UIImagePickerController()
164
+
165
+ picker.sourceType = .photoLibrary
166
+
167
+ picker.delegate = self
168
+
169
+ present(picker, animated: true)
170
+
171
+ self.present(picker, animated: true, completion: nil)
172
+
173
+
174
+
175
+ }
176
+
177
+
178
+
179
+ func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
180
+
181
+ if let selectedImage = info[.originalImage] as? UIImage{
182
+
183
+ usericonView.image = selectedImage
184
+
185
+ }
186
+
187
+ self.dismiss(animated: true)
188
+
189
+ }
190
+
191
+
192
+
193
+ func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
194
+
195
+ self.dismiss(animated: true, completion: nil)
196
+
197
+ }
198
+
199
+
200
+
201
+ //テキスト入力設定
202
+
203
+
204
+
205
+ func textFieldShouldReturn(_ textField: UITextField) -> Bool{
206
+
207
+ nickNameText = textField.text!
208
+
209
+ nickNameLabel.text = nickNameText
210
+
211
+
212
+
213
+ userNameText = textField.text!
214
+
215
+ userNameLabel.text = userNameText
216
+
217
+
218
+
219
+ sendEmailText = textField.text!
220
+
221
+ sendEmailLabel.text = sendEmailText
222
+
223
+
224
+
225
+ sendPhone = textField.text!
226
+
227
+ sendPhoneLabel.text = sendPhone
228
+
229
+
230
+
231
+ nextSendEmailText = textField.text!
232
+
233
+ nextSendEmailLabel.text = nextSendEmailText
234
+
235
+
236
+
237
+ nextSendPhone = textField.text!
238
+
239
+ nextSendPhoneLabel.text = nextSendPhone
240
+
241
+
242
+
243
+
244
+
245
+ textField.resignFirstResponder()
246
+
247
+
248
+
249
+ saveData(str: nickNameText)
250
+
251
+ saveData(str: userNameText)
252
+
253
+ saveData(str: sendEmailText)
254
+
255
+ saveData(str: sendPhone)
256
+
257
+ saveData(str: nextSendEmailText)
258
+
259
+ saveData(str: nextSendPhone)
260
+
261
+
262
+
263
+ return true
264
+
265
+
266
+
267
+ }
268
+
269
+
270
+
271
+ func saveData(str: String){
272
+
273
+ userDefaults.set(str, forKey: "NickName")
274
+
275
+ userDefaults.set(str, forKey: "UserName")
276
+
277
+ userDefaults.set(str, forKey: "SendEmail")
278
+
279
+ userDefaults.set(str, forKey: "SendPhone")
280
+
281
+ userDefaults.set(str, forKey: "NextSendEmail")
282
+
283
+ userDefaults.set(str, forKey: "NextSendPhone")
284
+
285
+ }
286
+
287
+
288
+
289
+ func readData(key: String) -> String {
290
+
291
+ let config = UserDefaults.standard
292
+
293
+ let str: String = config.string(forKey: key) ?? ""
294
+
295
+ return str
296
+
297
+ }
298
+
299
+
300
+
301
+
302
+
303
+ @IBAction func hozonButtton(_ sender : AnyObject) {
304
+
305
+
306
+
307
+
308
+
309
+ userDefaults.set(true, forKey: "NickName")
310
+
311
+ let str: String = userDefaults.object(forKey: "NickName") as! String
312
+
313
+ nickNameLabel.text = str
314
+
315
+
316
+
317
+ userDefaults.set(true, forKey: "UserName")
318
+
319
+ let _: String = userDefaults.object(forKey: "UserName") as! String
320
+
321
+ nickNameLabel.text = str
322
+
323
+
324
+
325
+ userDefaults.set(true, forKey: "SendEmail")
326
+
327
+ let _: String = userDefaults.object(forKey: "SendEmail") as! String
328
+
329
+ nickNameLabel.text = str
330
+
331
+
332
+
333
+ userDefaults.set(true, forKey: "SendPhone")
334
+
335
+ let _: String = userDefaults.object(forKey: "SendPhone") as! String
336
+
337
+ nickNameLabel.text = str
338
+
339
+
340
+
341
+ userDefaults.set(true, forKey: "NextSendemail")
342
+
343
+ let _: String = userDefaults.object(forKey: "NextSendEmail") as! String
344
+
345
+ nickNameLabel.text = str
346
+
347
+
348
+
349
+ userDefaults.set(true, forKey: "NextSendPhone")
350
+
351
+ let _: String = userDefaults.object(forKey: "NextSendPhone") as! String
352
+
353
+ nickNameLabel.text = str
354
+
355
+
356
+
357
+ nickNameLabel.text = str
358
+
359
+ userNameLabel.text = str
360
+
361
+ sendEmailLabel.text = str
362
+
363
+ sendPhoneLabel.text = str
364
+
365
+ nextSendEmailLabel.text = str
366
+
367
+ nextSendPhoneLabel.text = str
368
+
369
+
370
+
371
+
372
+
373
+ print()
374
+
375
+
376
+
377
+ }
378
+
379
+
380
+
381
+
382
+
383
+ }
384
+
385
+
386
+
387
+ コード
388
+
1
- ![textFieldに値を入れると全てのtextLabelに同じ値が入ってします。また、保存ボタンを押すとエラーになります。](fc099d3ae611e40a9da09adf72cc2b13.png)```import UIKit
389
+ ```![textFieldに値を入れると全てのtextLabelに同じ値が入ってします。また、保存ボタンを押すとエラーになります。](fc099d3ae611e40a9da09adf72cc2b13.png)```import UIKit
2
390
 
3
391
 
4
392
 

2

画像を追加しました。

2020/04/14 00:54

投稿

Eijirou
Eijirou

スコア6

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- ```import UIKit
1
+ ![textFieldに値を入れると全てのtextLabelに同じ値が入ってします。また、保存ボタンを押すとエラーになります。](fc099d3ae611e40a9da09adf72cc2b13.png)```import UIKit
2
2
 
3
3
 
4
4
 

1

エラーコード修正

2020/04/14 00:27

投稿

Eijirou
Eijirou

スコア6

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,66 @@
1
+ ```import UIKit
2
+
3
+
4
+
5
+ @UIApplicationMain
6
+
7
+ class AppDelegate: UIResponder, UIApplicationDelegate {
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
16
+
17
+ // Override point for customization after application launch.
18
+
19
+ return true
20
+
21
+ }
22
+
23
+
24
+
25
+ // MARK: UISceneSession Lifecycle
26
+
27
+
28
+
29
+ func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
30
+
31
+ // Called when a new scene session is being created.
32
+
33
+ // Use this method to select a configuration to create the new scene with.
34
+
35
+ return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
36
+
37
+ }
38
+
39
+
40
+
41
+ func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
42
+
43
+ // Called when the user discards a scene session.
44
+
45
+ // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
46
+
47
+ // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
48
+
49
+ }
50
+
51
+
52
+
53
+
54
+
55
+ }
56
+
57
+
58
+
59
+
60
+
61
+ コード
62
+
1
- ![入力画面![エラー画面](746c4177f0815a6990fb614a1190fcd3.png)](5c48c61b259040ad9cefd59d6847adf6.png)> ビルドは上手く行ったけど保存ボタンは押された後に
63
+ ```![入力画面![エラー画面](746c4177f0815a6990fb614a1190fcd3.png)](5c48c61b259040ad9cefd59d6847adf6.png)> ビルドは上手く行ったけど保存ボタンは押された後に
2
64
 
3
65
  エラーになります。
4
66