質問編集履歴
5
追記
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
4
追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -501,3 +501,5 @@
|
|
501
501
|
}
|
502
502
|
|
503
503
|
```
|
504
|
+
|
505
|
+
alertで入力し挿入するタイミングでsignalsigabrtになりました。
|
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -390,4 +390,114 @@
|
|
390
390
|
|
391
391
|
}
|
392
392
|
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
func alert(){
|
398
|
+
|
399
|
+
// テキストフィールド付きアラート表示
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
// OKボタンの設定
|
408
|
+
|
409
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
410
|
+
|
411
|
+
(action:UIAlertAction!) -> Void in
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
// OKを押した時入力されていたテキストを表示
|
416
|
+
|
417
|
+
if let textFields = alert.textFields {
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
422
|
+
|
423
|
+
for textField in textFields {
|
424
|
+
|
425
|
+
if self.cnt < 1{
|
426
|
+
|
427
|
+
self.item1.insert(textField.text!, at: 0)
|
428
|
+
|
429
|
+
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
430
|
+
|
431
|
+
}else if self.cnt < 2{
|
432
|
+
|
433
|
+
self.item2.insert(textField.text!, at: 0)
|
434
|
+
|
435
|
+
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
436
|
+
|
437
|
+
}else if self.cnt < 3{
|
438
|
+
|
439
|
+
self.item3.insert(textField.text!, at: 0)
|
440
|
+
|
441
|
+
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
442
|
+
|
443
|
+
}else if self.cnt < 4{
|
444
|
+
|
445
|
+
self.item4.insert(textField.text!, at: 0)
|
446
|
+
|
447
|
+
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
448
|
+
|
449
|
+
}else if self.cnt < 5{
|
450
|
+
|
451
|
+
self.item5.insert(textField.text!, at: 0)
|
452
|
+
|
453
|
+
self.mytableView.insertRows(at: [IndexPath(row: 0, section: 0)],with: UITableViewRowAnimation.automatic)
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
//print(textField.text!)
|
458
|
+
|
459
|
+
//self.Gesture()
|
460
|
+
|
461
|
+
//self.doubleclic()
|
462
|
+
|
463
|
+
}
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
})
|
468
|
+
|
469
|
+
alert.addAction(okAction)
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
// キャンセルボタンの設定
|
474
|
+
|
475
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
476
|
+
|
477
|
+
alert.addAction(cancelAction)
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
// テキストフィールドを追加
|
482
|
+
|
483
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
484
|
+
|
485
|
+
textField.placeholder = "テキスト"
|
486
|
+
|
487
|
+
})
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
// アラートを画面に表示
|
496
|
+
|
497
|
+
self.present(alert, animated: true, completion: nil)
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
}
|
502
|
+
|
393
503
|
```
|
2
コードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -228,28 +228,166 @@
|
|
228
228
|
|
229
229
|
### やりたい事
|
230
230
|
|
231
|
-
|
231
|
+
alertを使って一個ずつlabelを挿入できるようにしたい
|
232
|
-
|
233
|
-
|
232
|
+
|
234
|
-
|
235
|
-
|
233
|
+
|
236
|
-
|
237
|
-
1
|
238
|
-
|
239
|
-
2
|
240
|
-
|
241
|
-
3
|
242
|
-
|
243
|
-
4
|
244
|
-
|
245
|
-
やりたい事
|
246
|
-
|
247
|
-
1 2 3 4
|
248
234
|
|
249
235
|
|
250
236
|
|
251
237
|
**出来ている事**
|
252
238
|
|
239
|
+
横一列にセルを挿入出来た。
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
**困っていること**
|
244
|
+
|
245
|
+
alert一回で五つ同じlabelが挿入されてしまう。
|
246
|
+
|
253
|
-
|
247
|
+
どうしたら一個ずつlabelを挿入できるのかが分からなくて困っています。
|
248
|
+
|
249
|
+
|
250
|
+
|
254
|
-
|
251
|
+
```swift
|
252
|
+
|
253
|
+
//labelインスタンス
|
254
|
+
|
255
|
+
//label1
|
256
|
+
|
257
|
+
let label = UILabel()
|
258
|
+
|
259
|
+
label.backgroundColor = UIColor.darkGray
|
260
|
+
|
261
|
+
//label2
|
262
|
+
|
263
|
+
let label2 = UILabel()
|
264
|
+
|
265
|
+
label2.backgroundColor = UIColor.darkGray
|
266
|
+
|
267
|
+
//label3
|
268
|
+
|
269
|
+
let label3 = UILabel()
|
270
|
+
|
271
|
+
label3.backgroundColor = UIColor.darkGray
|
272
|
+
|
273
|
+
//label4
|
274
|
+
|
275
|
+
let label4 = UILabel()
|
276
|
+
|
277
|
+
label4.backgroundColor = UIColor.darkGray
|
278
|
+
|
279
|
+
//label5
|
280
|
+
|
281
|
+
let label5 = UILabel()
|
282
|
+
|
283
|
+
label5.backgroundColor = UIColor.darkGray
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
//丸みに対して
|
288
|
+
|
289
|
+
//label1
|
290
|
+
|
291
|
+
label.layer.cornerRadius = 5
|
292
|
+
|
293
|
+
label.layer.masksToBounds = true
|
294
|
+
|
295
|
+
label.sizeToFit()
|
296
|
+
|
255
|
-
|
297
|
+
label.translatesAutoresizingMaskIntoConstraints = false
|
298
|
+
|
299
|
+
cell.contentView.addSubview(label)
|
300
|
+
|
301
|
+
//label2
|
302
|
+
|
303
|
+
label2.layer.cornerRadius = 5
|
304
|
+
|
305
|
+
label2.layer.masksToBounds = true
|
306
|
+
|
307
|
+
label2.sizeToFit()
|
308
|
+
|
309
|
+
label2.translatesAutoresizingMaskIntoConstraints = false
|
310
|
+
|
311
|
+
cell.contentView.addSubview(label2)
|
312
|
+
|
313
|
+
//label3
|
314
|
+
|
315
|
+
label3.layer.cornerRadius = 5
|
316
|
+
|
317
|
+
label3.layer.masksToBounds = true
|
318
|
+
|
319
|
+
label3.sizeToFit()
|
320
|
+
|
321
|
+
label3.translatesAutoresizingMaskIntoConstraints = false
|
322
|
+
|
323
|
+
cell.contentView.addSubview(label3)
|
324
|
+
|
325
|
+
//label4
|
326
|
+
|
327
|
+
label4.layer.cornerRadius = 5
|
328
|
+
|
329
|
+
label4.layer.masksToBounds = true
|
330
|
+
|
331
|
+
label4.sizeToFit()
|
332
|
+
|
333
|
+
label4.translatesAutoresizingMaskIntoConstraints = false
|
334
|
+
|
335
|
+
cell.contentView.addSubview(label4)
|
336
|
+
|
337
|
+
//label5
|
338
|
+
|
339
|
+
label5.layer.cornerRadius = 5
|
340
|
+
|
341
|
+
label5.layer.masksToBounds = true
|
342
|
+
|
343
|
+
label5.sizeToFit()
|
344
|
+
|
345
|
+
label5.translatesAutoresizingMaskIntoConstraints = false
|
346
|
+
|
347
|
+
cell.contentView.addSubview(label5)
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
//座標的な
|
352
|
+
|
353
|
+
cell.contentView.leftAnchor.constraint(equalTo: label.leftAnchor, constant: -6).isActive = true
|
354
|
+
|
355
|
+
cell.contentView.leftAnchor.constraint(equalTo: label2.leftAnchor, constant: -70).isActive = true
|
356
|
+
|
357
|
+
cell.contentView.leftAnchor.constraint(equalTo: label3.leftAnchor, constant: -134).isActive = true
|
358
|
+
|
359
|
+
cell.contentView.leftAnchor.constraint(equalTo: label4.leftAnchor, constant: -198).isActive = true
|
360
|
+
|
361
|
+
cell.contentView.leftAnchor.constraint(equalTo: label5.leftAnchor, constant: -262).isActive = true
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
cell.contentView.heightAnchor.constraint(equalTo: label.heightAnchor, multiplier: 1).isActive = true
|
366
|
+
|
367
|
+
cell.contentView.heightAnchor.constraint(equalTo: label2.heightAnchor, multiplier: 1).isActive = true
|
368
|
+
|
369
|
+
cell.contentView.heightAnchor.constraint(equalTo: label3.heightAnchor, multiplier: 1).isActive = true
|
370
|
+
|
371
|
+
cell.contentView.heightAnchor.constraint(equalTo: label4.heightAnchor, multiplier: 1).isActive = true
|
372
|
+
|
373
|
+
cell.contentView.heightAnchor.constraint(equalTo: label5.heightAnchor, multiplier: 1).isActive = true
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
// itemに格納した値を設定
|
378
|
+
|
379
|
+
if indexPath.row < add.count {
|
380
|
+
|
381
|
+
label.text = add[indexPath.row]
|
382
|
+
|
383
|
+
label2.text = add[indexPath.row]
|
384
|
+
|
385
|
+
label3.text = add[indexPath.row]
|
386
|
+
|
387
|
+
label4.text = add[indexPath.row]
|
388
|
+
|
389
|
+
label5.text = add[indexPath.row]
|
390
|
+
|
391
|
+
}
|
392
|
+
|
393
|
+
```
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -184,15 +184,11 @@
|
|
184
184
|
|
185
185
|
@IBAction func addlabel(_ sender: Any) {
|
186
186
|
|
187
|
-
|
187
|
+
|
188
|
-
|
189
|
-
if key < 5 {
|
190
188
|
|
191
189
|
alert()
|
192
190
|
|
193
|
-
|
191
|
+
|
194
|
-
|
195
|
-
key += 1
|
196
192
|
|
197
193
|
|
198
194
|
|
@@ -232,7 +228,7 @@
|
|
232
228
|
|
233
229
|
### やりたい事
|
234
230
|
|
235
|
-
現状ではlabelをcellに挿入するときに一行に一個という形でlabelが挿入される形になっているがそれを一つのセルの中に
|
231
|
+
現状ではlabelをcellに挿入するときに一行に一個という形でlabelが挿入される形になっているがそれを一つのセルの中に3つだけlabelを挿入できるようにしたい
|
236
232
|
|
237
233
|
例)
|
238
234
|
|
@@ -254,6 +250,6 @@
|
|
254
250
|
|
255
251
|
**出来ている事**
|
256
252
|
|
257
|
-
挿入できる数
|
253
|
+
挿入できる数は制限が出来たが,どのようにすれば横一列に挿入できるのかが分からない。
|
258
254
|
|
259
255
|
個人的には配列は使うと出来るのではないかと思っているがどのようにコードを書けばいいか分からなくて困っています。
|