質問編集履歴

6

変更

2018/06/22 08:26

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes

5

変更

2018/06/22 08:26

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -210,6 +210,8 @@
210
210
 
211
211
 
212
212
 
213
+
214
+
213
215
  import UIKit
214
216
 
215
217
 
@@ -330,7 +332,75 @@
330
332
 
331
333
 
332
334
 
335
+
336
+
337
+
338
+
333
-
339
+ //改行ボタンが押された際に呼ばれる
340
+
341
+ func textFieldShouldReturn(_ textField: UITextField) -> Bool {
342
+
343
+ // 改行ボタンが押されたらKeyboardを閉じる処理.
344
+
345
+ textField.resignFirstResponder()
346
+
347
+
348
+
349
+ if textField.text == "" {
350
+
351
+ changeButton.isEnabled = false
352
+
353
+
354
+
355
+ } else {
356
+
357
+
358
+
359
+ changeButton.isEnabled = true
360
+
361
+ }
362
+
363
+
364
+
365
+ return true
366
+
367
+ }
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+ //UITextFieldが編集された後に呼ばれる
376
+
377
+ func textFieldDidEndEditing(_ textField: UITextField) {
378
+
379
+
380
+
381
+ if textField.text == "" {
382
+
383
+ changeButton.isEnabled = false
384
+
385
+
386
+
387
+ } else {
388
+
389
+
390
+
391
+ changeButton.isEnabled = true
392
+
393
+ }
394
+
395
+
396
+
397
+ }
398
+
399
+
400
+
401
+
402
+
403
+
334
404
 
335
405
  @objc func pushChange(sender:UIButton) {
336
406
 
@@ -342,35 +412,7 @@
342
412
 
343
413
  originVc.textFromModal = textField.text!
344
414
 
345
-
346
-
347
-
348
-
349
-
350
-
351
- let aaa = 1
415
+
352
-
353
- let text = textField.text!
354
-
355
-
356
-
357
- if text.count > aaa {
358
-
359
- changeButton.isEnabled = true
360
-
361
-
362
-
363
- } else if text.count < aaa {
364
-
365
-
366
-
367
- changeButton.isEnabled = false
368
-
369
- }
370
-
371
-
372
-
373
-
374
416
 
375
417
  self.dismiss(animated: true, completion: nil)
376
418
 
@@ -388,4 +430,6 @@
388
430
 
389
431
 
390
432
 
433
+
434
+
391
435
  ```

4

変更

2018/06/22 04:42

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [モーダルビューからデータを受け取る](https://picolica.com/2017/04/04/swift3-get-from-modalview/)ドキュメントを参考に、
6
6
 
7
- ModalViewControllerにあるpushChangeがタップされ、
7
+ ModalViewControllerにあるchangeButtonがタップされ、
8
8
 
9
9
  UITextField.textの文字が1文字を超えていれば、
10
10
 

3

変更

2018/06/22 03:29

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  [モーダルビューからデータを受け取る](https://picolica.com/2017/04/04/swift3-get-from-modalview/)ドキュメントを参考に、
6
6
 
7
- ModalViewControllerにあるdismissButtonがタップされ、
7
+ ModalViewControllerにあるpushChangeがタップされ、
8
8
 
9
9
  UITextField.textの文字が1文字を超えていれば、
10
10
 
@@ -64,7 +64,7 @@
64
64
 
65
65
 
66
66
 
67
- 他にfuncを作り、dismissButtonの前に判定などが必要なのでしょうか?試していますが分かりません。
67
+ 他にfuncを作り、changeButtonの前に判定などが必要なのでしょうか?試していますが分かりません。
68
68
 
69
69
  見ていただければとても助かります。よろしくお願いします。
70
70
 

2

変更

2018/06/22 03:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -72,7 +72,11 @@
72
72
 
73
73
 
74
74
 
75
+
76
+
77
+
78
+
75
- //6/22追記 参考ドキュメントに少し手を加えた下記コードを追加しました。
79
+ 6/22追記 参考ドキュメントに少し手を加えた下記コードを追加しました。
76
80
 
77
81
 
78
82
 

1

変更

2018/06/22 02:56

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -67,3 +67,321 @@
67
67
  他にfuncを作り、dismissButtonの前に判定などが必要なのでしょうか?試していますが分かりません。
68
68
 
69
69
  見ていただければとても助かります。よろしくお願いします。
70
+
71
+
72
+
73
+
74
+
75
+ //6/22追記 参考ドキュメントに少し手を加えた下記コードを追加しました。
76
+
77
+
78
+
79
+ ```ここに言語を入力
80
+
81
+
82
+
83
+ import UIKit
84
+
85
+
86
+
87
+ class HomeViewController: UIViewController {
88
+
89
+
90
+
91
+
92
+
93
+ var textFromModal = "" {
94
+
95
+ didSet {
96
+
97
+
98
+
99
+ updatelabel(text: textFromModal)
100
+
101
+ }
102
+
103
+ }
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+ var textLabel = UILabel()
112
+
113
+
114
+
115
+ override func viewDidLoad() {
116
+
117
+ super.viewDidLoad()
118
+
119
+
120
+
121
+ view.backgroundColor = .white
122
+
123
+ set()
124
+
125
+ }
126
+
127
+
128
+
129
+
130
+
131
+ func set() {
132
+
133
+ textLabel = UILabel(frame: CGRect(x: 0, y: 0, width: view.bounds.width - 20, height: 30))
134
+
135
+ textLabel.center = CGPoint(x: view.center.x, y: view.center.y - 50)
136
+
137
+ textLabel.textAlignment = .center
138
+
139
+
140
+
141
+ textLabel.text = ""
142
+
143
+ view.addSubview(textLabel)
144
+
145
+
146
+
147
+ //
148
+
149
+
150
+
151
+ let modalButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
152
+
153
+ modalButton.center = view.center
154
+
155
+ modalButton.setTitle("開く", for: .normal)
156
+
157
+ modalButton.setTitleColor(UIColor.blue, for: .normal)
158
+
159
+ modalButton.addTarget(self, action: #selector(pushModal(sender:)), for: .touchUpInside)
160
+
161
+ view.addSubview(modalButton)
162
+
163
+ }
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+ @objc func pushModal(sender:UIButton) {
172
+
173
+
174
+
175
+ let modal = ModalViewController(nibName: nil, bundle: nil)
176
+
177
+ modal.modalTransitionStyle = .crossDissolve
178
+
179
+ present(modal, animated: true, completion: nil)
180
+
181
+ }
182
+
183
+
184
+
185
+
186
+
187
+ func updatelabel(text: String) {
188
+
189
+ textLabel.text = "I'm, (text)"
190
+
191
+ }
192
+
193
+
194
+
195
+ }
196
+
197
+
198
+
199
+ ```
200
+
201
+
202
+
203
+ ```ここに言語を入力
204
+
205
+
206
+
207
+
208
+
209
+ import UIKit
210
+
211
+
212
+
213
+ class ModalViewController: UIViewController, UITextFieldDelegate {
214
+
215
+
216
+
217
+
218
+
219
+ var changeButton = UIButton()
220
+
221
+
222
+
223
+ var textField = UITextField()
224
+
225
+
226
+
227
+ override func viewDidLoad() {
228
+
229
+ super.viewDidLoad()
230
+
231
+
232
+
233
+ set()
234
+
235
+ }
236
+
237
+
238
+
239
+
240
+
241
+ func set() {
242
+
243
+ view.backgroundColor = .gray
244
+
245
+
246
+
247
+
248
+
249
+ let cancelButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
250
+
251
+ cancelButton.center = CGPoint(x: view.center.x - 100, y: view.center.y)
252
+
253
+ cancelButton.setTitle("キャンセル", for: .normal)
254
+
255
+ cancelButton.setTitleColor(UIColor.black, for: .normal)
256
+
257
+ cancelButton.addTarget(self, action: #selector(pushDismiss(sender:)), for: .touchUpInside)
258
+
259
+ view.addSubview(cancelButton)
260
+
261
+
262
+
263
+
264
+
265
+ //
266
+
267
+
268
+
269
+
270
+
271
+ changeButton = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
272
+
273
+ changeButton.center = CGPoint(x: view.center.x + 100, y: view.center.y)
274
+
275
+ changeButton.setTitle("変更", for: .normal)
276
+
277
+ changeButton.setTitleColor(UIColor.black, for: .normal)
278
+
279
+ changeButton.addTarget(self, action: #selector(pushChange(sender:)), for: .touchUpInside)
280
+
281
+ view.addSubview(changeButton)
282
+
283
+
284
+
285
+ //111
286
+
287
+ textField.delegate = self
288
+
289
+ textField.text = ""
290
+
291
+
292
+
293
+ textField = UITextField(frame: CGRect(x: 0, y: 0, width: view.bounds.width - 20, height: 30))
294
+
295
+ textField.center = CGPoint(x: view.center.x, y: view.center.y + 50)
296
+
297
+ textField.placeholder = "input your name"
298
+
299
+ textField.backgroundColor = .white
300
+
301
+ view.addSubview(textField)
302
+
303
+
304
+
305
+
306
+
307
+ }
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+ @objc func pushDismiss(sender:UIButton) {
318
+
319
+ self.dismiss(animated: true, completion: nil)
320
+
321
+ }
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+ @objc func pushChange(sender:UIButton) {
332
+
333
+ textField.resignFirstResponder()
334
+
335
+ //強制ダウンキャスト
336
+
337
+ let originVc = presentingViewController as! HomeViewController
338
+
339
+ originVc.textFromModal = textField.text!
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+ let aaa = 1
348
+
349
+ let text = textField.text!
350
+
351
+
352
+
353
+ if text.count > aaa {
354
+
355
+ changeButton.isEnabled = true
356
+
357
+
358
+
359
+ } else if text.count < aaa {
360
+
361
+
362
+
363
+ changeButton.isEnabled = false
364
+
365
+ }
366
+
367
+
368
+
369
+
370
+
371
+ self.dismiss(animated: true, completion: nil)
372
+
373
+
374
+
375
+ }
376
+
377
+
378
+
379
+
380
+
381
+ }
382
+
383
+
384
+
385
+
386
+
387
+ ```