teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

ソースコードの追加

2021/01/07 16:08

投稿

Ogikubo
Ogikubo

スコア1

title CHANGED
File without changes
body CHANGED
@@ -73,9 +73,60 @@
73
73
  }
74
74
  }
75
75
  ```
76
+ ```swift
77
+ override func numberOfSections(in tableView: UITableView) -> Int {
78
+ return 1
79
+ }
76
80
 
81
+ override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
82
+ if self.seachBar.text == "" {
83
+ return timeLines.count
84
+ }else{
85
+ return seachedtimeLines.count
86
+ }
87
+
88
+ }
89
+
90
+ override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
91
+ let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TimeLineCell
92
+ if seachBar.text == "" {
93
+ cell.timeLineModel = self.timeLines[indexPath.row]
94
+ }else{
95
+ cell.timeLineModel = self.seachedtimeLines[indexPath.row]
96
+ }
97
+ return cell
98
+ }
99
+
100
+ override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
101
+
102
+ let selectedCell = tableView.cellForRow(at: indexPath)
77
103
 
104
+ if seachBar.text == ""{
105
+ let selectedTimeLine = timeLines[indexPath.row]
106
+ performSegue(withIdentifier: "detail", sender: selectedTimeLine)
107
+ }else{
108
+ let selectedTimeLine = seachedtimeLines[indexPath.row]
109
+ performSegue(withIdentifier: "detail", sender: selectedTimeLine)
110
+ }
78
111
 
112
+ }
113
+
114
+ override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
115
+
116
+ if segue.identifier == "detail" {
117
+
118
+ let detailViewController = segue.destination as! DetailViewController
119
+ detailViewController.pushedTimeLine = sender as? TimeLineModel
120
+ }
121
+ }
122
+ override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
123
+ return 82
124
+ }
125
+ ```
126
+
127
+
128
+
129
+
79
130
  ### 補足情報(FW/ツールのバージョンなど)
80
131
 
81
132
  他の場所でshowAllDataを読んだ場合は表示できます。