質問編集履歴
3
add explain
title
CHANGED
File without changes
|
body
CHANGED
@@ -110,6 +110,7 @@
|
|
110
110
|
|
111
111
|
```
|
112
112
|
|
113
|
+
Segueを削除して新しくファイルを4つ作りそれぞれのViewに割り当てました。
|
113
114
|
[GyazoGIF参考動画](https://gyazo.com/63f1adec22cfd08fac21ae4628f9227c)
|
114
115
|
変更後
|
115
116
|
```
|
2
add video
title
CHANGED
File without changes
|
body
CHANGED
@@ -109,6 +109,8 @@
|
|
109
109
|
}
|
110
110
|
|
111
111
|
```
|
112
|
+
|
113
|
+
[GyazoGIF参考動画](https://gyazo.com/63f1adec22cfd08fac21ae4628f9227c)
|
112
114
|
変更後
|
113
115
|
```
|
114
116
|
import UIKit
|
1
add code
title
CHANGED
File without changes
|
body
CHANGED
@@ -108,4 +108,69 @@
|
|
108
108
|
}
|
109
109
|
}
|
110
110
|
|
111
|
+
```
|
112
|
+
変更後
|
113
|
+
```
|
114
|
+
import UIKit
|
115
|
+
|
116
|
+
private struct Segue {
|
117
|
+
var title = ""
|
118
|
+
let `class` : AnyClass
|
119
|
+
}
|
120
|
+
|
121
|
+
class FirstViewController: UIViewController {
|
122
|
+
|
123
|
+
@IBOutlet weak var tableView: UITableView!
|
124
|
+
|
125
|
+
private var segues: [Segue] = [
|
126
|
+
|
127
|
+
Segue(title: "aaaaaaaa", class: Segue0ViewController.self),
|
128
|
+
Segue(title: "bbbbbbbb", class: Segue1ViewController.self),
|
129
|
+
Segue(title: "cccccccc", class: Segue2ViewController.self),
|
130
|
+
Segue(title: "dddddddd", class: Segue3ViewController.self)
|
131
|
+
]
|
132
|
+
|
133
|
+
override func viewDidLoad() {
|
134
|
+
super.viewDidLoad()
|
135
|
+
|
136
|
+
self.tableView.rowHeight = 60
|
137
|
+
|
138
|
+
tableView.delegate = self
|
139
|
+
tableView.dataSource = self
|
140
|
+
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
extension FirstViewController: UITableViewDelegate {
|
145
|
+
|
146
|
+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
147
|
+
|
148
|
+
let segue = self.segues[indexPath.row]
|
149
|
+
|
150
|
+
let vcClass = segue.class as! UIViewController.Type
|
151
|
+
let vc = vcClass.init()
|
152
|
+
|
153
|
+
self.navigationController?.pushViewController(vc, animated: true)
|
154
|
+
tableView.deselectRow(at: indexPath, animated: true)
|
155
|
+
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
extension FirstViewController: UITableViewDataSource {
|
160
|
+
|
161
|
+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
162
|
+
return self.segues.count
|
163
|
+
}
|
164
|
+
|
165
|
+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
166
|
+
|
167
|
+
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
|
168
|
+
let segue = self.segues[indexPath.row]
|
169
|
+
cell.textLabel?.text = segue.title
|
170
|
+
// cell.accessoryType = UITableViewCell.AccessoryType.disclosureIndicator
|
171
|
+
|
172
|
+
return cell
|
173
|
+
}
|
174
|
+
}
|
175
|
+
|
111
176
|
```
|