質問編集履歴

1

追記

2020/10/05 04:55

投稿

sunglass
sunglass

スコア303

test CHANGED
File without changes
test CHANGED
@@ -14,9 +14,51 @@
14
14
 
15
15
 
16
16
 
17
+ 追記:カスタムセルは使っていません。。
18
+
19
+
20
+
17
21
  ```ここに言語を入力
18
22
 
23
+ import UIKit
24
+
25
+ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UINavigationControllerDelegate {
26
+
27
+
28
+
29
+ @IBOutlet weak var tableView: UITableView!
30
+
31
+ @IBOutlet weak var shadowView: UIView!
32
+
33
+ @IBOutlet weak var tableHeight: NSLayoutConstraint!
34
+
35
+
36
+
37
+ @IBOutlet weak var itemAddField: UITextField!
38
+
39
+
40
+
41
+ let customUITextField:CustomTextField = CustomTextField()
42
+
43
+
44
+
45
+ var title: String = ""
46
+
47
+
48
+
49
+ var List = ["testtest",
50
+
51
+ "testtest",
52
+
53
+ "testtest",
54
+
55
+ "testtest",
56
+
57
+ ]
58
+
59
+
60
+
19
- let sectionTitles = ["News"]
61
+ let sectionTitles = ["News"]
20
62
 
21
63
 
22
64
 
@@ -54,4 +96,176 @@
54
96
 
55
97
  }
56
98
 
99
+
100
+
101
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
102
+
103
+ return List.count
104
+
105
+ }
106
+
107
+
108
+
109
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
110
+
111
+ let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
112
+
113
+
114
+
115
+ cell.textLabel?.text = List[indexPath.row]
116
+
117
+
118
+
119
+ return cell
120
+
121
+ }
122
+
123
+
124
+
125
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
126
+
127
+
128
+
129
+
130
+
131
+ self.title = List[indexPath.row]
132
+
133
+
134
+
135
+ let nextVC = self.storyboard?.instantiateViewController(withIdentifier: "navigationPushView") as! SecondViewController
136
+
137
+ nextVC.data = self.title
138
+
139
+ self.navigationController?.pushViewController(nextVC, animated: true)
140
+
141
+
142
+
143
+ // セルの選択を解除
144
+
145
+ tableView.deselectRow(at: indexPath, animated: true)
146
+
147
+ }
148
+
149
+
150
+
151
+ func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
152
+
153
+ {
154
+
155
+ return true
156
+
157
+ }
158
+
159
+
160
+
161
+ //スワイプしたセルを削除
162
+
163
+ func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
164
+
165
+ if editingStyle == UITableViewCell.EditingStyle.delete {
166
+
167
+ List.remove(at: indexPath.row)
168
+
169
+ tableView.deleteRows(at: [indexPath as IndexPath], with: UITableView.RowAnimation.automatic)
170
+
171
+ }
172
+
173
+ }
174
+
175
+
176
+
177
+ override func viewDidLoad() {
178
+
179
+ super.viewDidLoad()
180
+
181
+ // Do any additional setup after loading the view, typically from a nib.
182
+
183
+
184
+
185
+ // for textField
186
+
187
+ itemAddField.layer.masksToBounds = false
188
+
189
+ itemAddField.layer.shadowRadius = 5.0
190
+
191
+ itemAddField.layer.shadowColor = UIColor.blue.cgColor
192
+
193
+ itemAddField.layer.shadowOffset = CGSize(width: 0, height: 0)
194
+
195
+ itemAddField.layer.shadowOpacity = 0.1
196
+
197
+
198
+
199
+ // for tableview
200
+
201
+ self.tableView.layer.cornerRadius = 8
202
+
203
+ self.tableView.clipsToBounds = true
204
+
205
+
206
+
207
+ // for shadow UIView
208
+
209
+ shadowView.layer.cornerRadius = 8.0
210
+
211
+ shadowView.layer.shadowColor = UIColor.blue.cgColor
212
+
213
+ shadowView.layer.shadowOffset = CGSize(width: 0.0, height: 0.0)
214
+
215
+ shadowView.layer.shadowOpacity = 0.1
216
+
217
+ shadowView.layer.shadowRadius = 8.0
218
+
219
+ self.tableView.separatorInset.left = 0
220
+
221
+
222
+
223
+ // not scroll
224
+
225
+ //self.tableView.isScrollEnabled = false
226
+
227
+
228
+
229
+ self.tableView.dataSource = self
230
+
231
+ self.tableView.delegate = self
232
+
233
+
234
+
235
+ self.tableView.reloadData()
236
+
237
+ view.layoutIfNeeded()
238
+
239
+ view.updateConstraints()
240
+
241
+
242
+
243
+ self.navigationController?.setNavigationBarHidden(true, animated: true)
244
+
245
+ self.navigationController?.navigationBar.isHidden = true
246
+
247
+ self.navigationController?.isNavigationBarHidden = true
248
+
249
+
250
+
251
+ }
252
+
253
+
254
+
255
+ override func viewWillDisappear(_ animated: Bool) {
256
+
257
+ super.viewWillDisappear(animated)
258
+
259
+
260
+
261
+ tableHeight.constant = CGFloat(tableView.contentSize.height)
262
+
263
+ }
264
+
265
+ }
266
+
267
+
268
+
269
+
270
+
57
271
  ```