回答編集履歴
2
一部修正しました。
answer
CHANGED
@@ -23,4 +23,25 @@
|
|
23
23
|
@objc func tapped(_ sender: Any) {
|
24
24
|
print("tap")
|
25
25
|
}
|
26
|
+
```
|
27
|
+
|
28
|
+
```
|
29
|
+
|
30
|
+
// セクションヘッダーの設定
|
31
|
+
|
32
|
+
// セクション数
|
33
|
+
func numberOfSections(in tableView: UITableView) -> Int {
|
34
|
+
return 1
|
35
|
+
}
|
36
|
+
|
37
|
+
// セクションヘッダーの高さ
|
38
|
+
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
39
|
+
return 50
|
40
|
+
}
|
41
|
+
|
42
|
+
// セクションヘッダーのタイトル
|
43
|
+
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
|
44
|
+
return "ヘッダー"
|
45
|
+
}
|
46
|
+
|
26
47
|
```
|
1
一部追記しました。
answer
CHANGED
@@ -1,4 +1,26 @@
|
|
1
1
|
「ヘッダー」と出力されている箇所をセクションヘッダーとして、その上にtableViewのtableHeaderViewを設定する方法だとイメージとは異なりますでしょうか?
|
2
2
|
|
3
3
|
ヘッダーを設定する参考記事:
|
4
|
-
[https://qiita.com/nakamurau1@github/items/301b69522c32254617ad](https://qiita.com/nakamurau1@github/items/301b69522c32254617ad)
|
4
|
+
[https://qiita.com/nakamurau1@github/items/301b69522c32254617ad](https://qiita.com/nakamurau1@github/items/301b69522c32254617ad)
|
5
|
+
|
6
|
+
【追記】
|
7
|
+
```
|
8
|
+
// viewDidLoadの中
|
9
|
+
|
10
|
+
// TableViewのヘッダーを設定
|
11
|
+
let headerView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
|
12
|
+
|
13
|
+
headerView.backgroundColor = .red
|
14
|
+
tableView.tableHeaderView = headerView
|
15
|
+
|
16
|
+
let tap = UITapGestureRecognizer(target: self, action: #selector(tapped(_:)))
|
17
|
+
headerView.addGestureRecognizer(tap)
|
18
|
+
```
|
19
|
+
|
20
|
+
```
|
21
|
+
// タップした時に呼び出されるアクション
|
22
|
+
|
23
|
+
@objc func tapped(_ sender: Any) {
|
24
|
+
print("tap")
|
25
|
+
}
|
26
|
+
```
|