質問編集履歴
6
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -321,145 +321,3 @@
|
|
321
321
|
```
|
322
322
|
|
323
323
|
教えていただい通りにこのようにして見たのですがやっぱり[cell 追加]以外はタップしてもアラートテキストが出てくるのですがこの他にさらに別のメソッドが必要なでしょうか?
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
**編集したコード**
|
328
|
-
|
329
|
-
```
|
330
|
-
|
331
|
-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
332
|
-
|
333
|
-
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
334
|
-
|
335
|
-
cell.textLabel?.text = kei[indexPath.row]
|
336
|
-
|
337
|
-
cell.selectionStyle = (kei.count > (indexPath.row + 1)) ? .none : .blue
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
if kei.count > (indexPath.row + 1) {
|
342
|
-
|
343
|
-
cell.isUserInteractionEnabled = false
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
}
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
return cell
|
352
|
-
|
353
|
-
}
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
358
|
-
|
359
|
-
if kei.count > (indexPath.row + 1) {
|
360
|
-
|
361
|
-
return nil
|
362
|
-
|
363
|
-
}
|
364
|
-
|
365
|
-
return indexPath
|
366
|
-
|
367
|
-
}
|
368
|
-
|
369
|
-
```
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
![イメージ説明](332bc04caff7a32cf57ba80dc6fca221.png)
|
374
|
-
|
375
|
-
![イメージ説明](5850dc266e1be1580b3827edb159e223.png)
|
376
|
-
|
377
|
-
![イメージ説明](7965d5a0bb4baf36ac4eda15dcd6cc49.png)
|
378
|
-
|
379
|
-
```ここに言語を入力
|
380
|
-
|
381
|
-
func tableView(_ tableView: UITableView, didSelectRowAtIndexPath: IndexPath){
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
if kei.count > ([indexPath.row]) {
|
386
|
-
|
387
|
-
return nil
|
388
|
-
|
389
|
-
}
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
// OKボタンの設定
|
398
|
-
|
399
|
-
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
400
|
-
|
401
|
-
(action:UIAlertAction!) -> Void in
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
// OKを押した時入力されていたテキストを表示
|
406
|
-
|
407
|
-
if let textFields = alert.textFields {
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
// アラートに含まれるすべてのテキストフィールドを調べる
|
412
|
-
|
413
|
-
for textField in textFields {
|
414
|
-
|
415
|
-
self.kei.insert(textField.text!, at:0)
|
416
|
-
|
417
|
-
//self.kei.append(textField.text!)
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
self.mytableView.reloadData()
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
})
|
428
|
-
|
429
|
-
alert.addAction(okAction)
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
// キャンセルボタンの設定
|
434
|
-
|
435
|
-
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
436
|
-
|
437
|
-
alert.addAction(cancelAction)
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
// テキストフィールドを追加
|
442
|
-
|
443
|
-
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
444
|
-
|
445
|
-
textField.placeholder = "テキスト"
|
446
|
-
|
447
|
-
})
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
// アラートを画面に表示
|
458
|
-
|
459
|
-
self.present(alert, animated: true, completion: nil)
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
}
|
464
|
-
|
465
|
-
```
|
5
こーどの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -375,3 +375,91 @@
|
|
375
375
|
![イメージ説明](5850dc266e1be1580b3827edb159e223.png)
|
376
376
|
|
377
377
|
![イメージ説明](7965d5a0bb4baf36ac4eda15dcd6cc49.png)
|
378
|
+
|
379
|
+
```ここに言語を入力
|
380
|
+
|
381
|
+
func tableView(_ tableView: UITableView, didSelectRowAtIndexPath: IndexPath){
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
if kei.count > ([indexPath.row]) {
|
386
|
+
|
387
|
+
return nil
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
let alert = UIAlertController(title: "タイトル", message: "メッセージ", preferredStyle: .alert)
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
// OKボタンの設定
|
398
|
+
|
399
|
+
let okAction = UIAlertAction(title: "OK", style: .default, handler: {
|
400
|
+
|
401
|
+
(action:UIAlertAction!) -> Void in
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
// OKを押した時入力されていたテキストを表示
|
406
|
+
|
407
|
+
if let textFields = alert.textFields {
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
// アラートに含まれるすべてのテキストフィールドを調べる
|
412
|
+
|
413
|
+
for textField in textFields {
|
414
|
+
|
415
|
+
self.kei.insert(textField.text!, at:0)
|
416
|
+
|
417
|
+
//self.kei.append(textField.text!)
|
418
|
+
|
419
|
+
}
|
420
|
+
|
421
|
+
self.mytableView.reloadData()
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
})
|
428
|
+
|
429
|
+
alert.addAction(okAction)
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
// キャンセルボタンの設定
|
434
|
+
|
435
|
+
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
|
436
|
+
|
437
|
+
alert.addAction(cancelAction)
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
// テキストフィールドを追加
|
442
|
+
|
443
|
+
alert.addTextField(configurationHandler: {(textField: UITextField!) -> Void in
|
444
|
+
|
445
|
+
textField.placeholder = "テキスト"
|
446
|
+
|
447
|
+
})
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
alert.view.setNeedsLayout() // シミュレータの種類によっては、これがないと警告が発生
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
// アラートを画面に表示
|
458
|
+
|
459
|
+
self.present(alert, animated: true, completion: nil)
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
}
|
464
|
+
|
465
|
+
```
|
4
画像の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -373,3 +373,5 @@
|
|
373
373
|
![イメージ説明](332bc04caff7a32cf57ba80dc6fca221.png)
|
374
374
|
|
375
375
|
![イメージ説明](5850dc266e1be1580b3827edb159e223.png)
|
376
|
+
|
377
|
+
![イメージ説明](7965d5a0bb4baf36ac4eda15dcd6cc49.png)
|
3
コードとが画像の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -270,11 +270,7 @@
|
|
270
270
|
|
271
271
|
|
272
272
|
|
273
|
-
|
273
|
+
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
![イメージ説明](276bfd317033e426e0e5aba2bd29f1a6.png)
|
278
274
|
|
279
275
|
|
280
276
|
|
@@ -325,3 +321,55 @@
|
|
325
321
|
```
|
326
322
|
|
327
323
|
教えていただい通りにこのようにして見たのですがやっぱり[cell 追加]以外はタップしてもアラートテキストが出てくるのですがこの他にさらに別のメソッドが必要なでしょうか?
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
**編集したコード**
|
328
|
+
|
329
|
+
```
|
330
|
+
|
331
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
332
|
+
|
333
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
|
334
|
+
|
335
|
+
cell.textLabel?.text = kei[indexPath.row]
|
336
|
+
|
337
|
+
cell.selectionStyle = (kei.count > (indexPath.row + 1)) ? .none : .blue
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
if kei.count > (indexPath.row + 1) {
|
342
|
+
|
343
|
+
cell.isUserInteractionEnabled = false
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
return cell
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
358
|
+
|
359
|
+
if kei.count > (indexPath.row + 1) {
|
360
|
+
|
361
|
+
return nil
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
return indexPath
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
```
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
![イメージ説明](332bc04caff7a32cf57ba80dc6fca221.png)
|
374
|
+
|
375
|
+
![イメージ説明](5850dc266e1be1580b3827edb159e223.png)
|
2
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -275,3 +275,53 @@
|
|
275
275
|
|
276
276
|
|
277
277
|
![イメージ説明](276bfd317033e426e0e5aba2bd29f1a6.png)
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
```ここに言語を入力
|
282
|
+
|
283
|
+
func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
switch indexPath.row {
|
288
|
+
|
289
|
+
case 0:
|
290
|
+
|
291
|
+
return indexPath
|
292
|
+
|
293
|
+
// 選択不可にしたい場合は"nil"を返す
|
294
|
+
|
295
|
+
case 1:
|
296
|
+
|
297
|
+
return nil
|
298
|
+
|
299
|
+
default:
|
300
|
+
|
301
|
+
return indexPath
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
if kei.count > (indexPath.row + 1) {
|
316
|
+
|
317
|
+
return nil
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
return indexPath
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
```
|
326
|
+
|
327
|
+
教えていただい通りにこのようにして見たのですがやっぱり[cell 追加]以外はタップしてもアラートテキストが出てくるのですがこの他にさらに別のメソッドが必要なでしょうか?
|
1
画像の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -267,3 +267,11 @@
|
|
267
267
|
**やりたいこと**
|
268
268
|
|
269
269
|
他の人の質問を参考にしてcellをタップするとアラートテキストが表示され入力出来るようになったのですが理想としては[cell 追加]以外はタップしても何も入力できないようにしたいです。
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
!![イメージ説明](b447026469d7fd833f5a55ac55084681.png)明]
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
![イメージ説明](276bfd317033e426e0e5aba2bd29f1a6.png)
|