回答編集履歴

2

一部修正しました。

2018/03/19 21:24

投稿

newmt
newmt

スコア1277

test CHANGED
@@ -49,3 +49,45 @@
49
49
  }
50
50
 
51
51
  ```
52
+
53
+
54
+
55
+ ```
56
+
57
+
58
+
59
+ // セクションヘッダーの設定
60
+
61
+
62
+
63
+ // セクション数
64
+
65
+ func numberOfSections(in tableView: UITableView) -> Int {
66
+
67
+ return 1
68
+
69
+ }
70
+
71
+
72
+
73
+ // セクションヘッダーの高さ
74
+
75
+ func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
76
+
77
+ return 50
78
+
79
+ }
80
+
81
+
82
+
83
+ // セクションヘッダーのタイトル
84
+
85
+ func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
86
+
87
+ return "ヘッダー"
88
+
89
+ }
90
+
91
+
92
+
93
+ ```

1

一部追記しました。

2018/03/19 21:24

投稿

newmt
newmt

スコア1277

test CHANGED
@@ -5,3 +5,47 @@
5
5
  ヘッダーを設定する参考記事:
6
6
 
7
7
  [https://qiita.com/nakamurau1@github/items/301b69522c32254617ad](https://qiita.com/nakamurau1@github/items/301b69522c32254617ad)
8
+
9
+
10
+
11
+ 【追記】
12
+
13
+ ```
14
+
15
+ // viewDidLoadの中
16
+
17
+
18
+
19
+ // TableViewのヘッダーを設定
20
+
21
+ let headerView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
22
+
23
+
24
+
25
+ headerView.backgroundColor = .red
26
+
27
+ tableView.tableHeaderView = headerView
28
+
29
+
30
+
31
+ let tap = UITapGestureRecognizer(target: self, action: #selector(tapped(_:)))
32
+
33
+ headerView.addGestureRecognizer(tap)
34
+
35
+ ```
36
+
37
+
38
+
39
+ ```
40
+
41
+ // タップした時に呼び出されるアクション
42
+
43
+
44
+
45
+ @objc func tapped(_ sender: Any) {
46
+
47
+ print("tap")
48
+
49
+ }
50
+
51
+ ```