質問編集履歴
2
不要な画像の削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -62,14 +62,7 @@
|
|
62
62
|
|
63
63
|

|
64
64
|
|
65
|
-
EditViewControllerのClassとStoryboardID
|
66
65
|
|
67
|
-

|
68
|
-
|
69
|
-
Segueのidentifier
|
70
|
-
|
71
|
-

|
72
|
-
|
73
66
|
修正したViewController.swift
|
74
67
|
|
75
68
|
```Swift
|
1
変更後のコードと画像の追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -38,21 +38,59 @@
|
|
38
38
|
if segue.identifier == "transEdit" {
|
39
39
|
|
40
40
|
let editVC = segue.destination as! EditViewController
|
41
|
-
editVC.editContentLabel.text = displayedContentList[
|
41
|
+
editVC.editContentLabel.text = displayedContentList[indexPath.row]
|
42
42
|
|
43
43
|
}
|
44
44
|
```
|
45
45
|
|
46
|
-
その結果、下記の
|
46
|
+
その結果、下記のエラーメッセージが表示されました。
|
47
47
|
|
48
48
|
```ここに言語を入力
|
49
49
|
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
|
50
|
-
|
51
|
-
Instance member 'row' cannot be used on type 'IndexPath'
|
52
50
|
```
|
53
51
|
|
52
|
+
|
54
53
|
**考えたこと**
|
55
54
|
|
56
|
-
`
|
55
|
+
`indexPath`はTableViewの要素?なので、`prepare(for segue)`メソッドの中で使えないのではないかと考えましたが、他のやり方が思いつきません。すでに他の画面遷移を実装している状態で、`didSelectRowAt`から画面遷移ができるようにする良い方法はあるでしょうか?
|
57
56
|
|
58
|
-
ご教授願います。
|
57
|
+
ご教授願います。
|
58
|
+
|
59
|
+
**追記**
|
60
|
+
|
61
|
+
Main.storyboardの画面遷移図です。今回繋げたいのは、左上のViewControllerと左下のEditViewControllerです。
|
62
|
+
|
63
|
+

|
64
|
+
|
65
|
+
EditViewControllerのClassとStoryboardID
|
66
|
+
|
67
|
+

|
68
|
+
|
69
|
+
Segueのidentifier
|
70
|
+
|
71
|
+

|
72
|
+
|
73
|
+
修正したViewController.swift
|
74
|
+
|
75
|
+
```Swift
|
76
|
+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
77
|
+
|
78
|
+
guard let editVC = storyboard?.instantiateViewController(identifier: "EditViewController") as? EditViewController else { return }
|
79
|
+
editVC.editContentLabel.text = displayedContentList[indexPath.row]
|
80
|
+
self.performSegue(withIdentifier: "transEdit", sender: nil)
|
81
|
+
|
82
|
+
}
|
83
|
+
|
84
|
+
```
|
85
|
+
|
86
|
+
EditViewController.swift
|
87
|
+
|
88
|
+
```Swift
|
89
|
+
class EditViewController: UIViewController {
|
90
|
+
|
91
|
+
@IBOutlet weak var editContentLabel: UILabel!
|
92
|
+
|
93
|
+
override func viewDidLoad() {
|
94
|
+
super.viewDidLoad()
|
95
|
+
}
|
96
|
+
```
|