回答編集履歴
4
。
test
CHANGED
@@ -112,6 +112,10 @@
|
|
112
112
|
|
113
113
|
|
114
114
|
|
115
|
+
となっています。
|
116
|
+
|
117
|
+
|
118
|
+
|
115
119
|
```swift
|
116
120
|
|
117
121
|
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
3
なんやかんやで。
test
CHANGED
@@ -87,3 +87,91 @@
|
|
87
87
|
```
|
88
88
|
|
89
89
|
|
90
|
+
|
91
|
+
# 色々と試した挙句
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
これがシンプルで良いという結論に。高さはあくまで**おまかせ**で中身を変更します。
|
96
|
+
|
97
|
+
今のままだと下のマージンが広くなってしまいますが、気になるようならマージンの制約値を変えてやればいいと思います。(たぶん)
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
勝手に色々と追加していますが、
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
* labelTop,labelBottomは、それぞれ上ラベル、下ラベル
|
106
|
+
|
107
|
+
* msgTop,msgBottomは、それぞれ上メッセージ、下メッセージ
|
108
|
+
|
109
|
+
* viewBarは下線(区切り線)のUIView
|
110
|
+
|
111
|
+
* toggleは配列にしています
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
```swift
|
116
|
+
|
117
|
+
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCell
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
//上は常に全文表示
|
126
|
+
|
127
|
+
cell.labelTop.text = msgTop[indexPath.row]
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
//線から下は開いているときだけ
|
132
|
+
|
133
|
+
if toggle[indexPath.row] {
|
134
|
+
|
135
|
+
//close
|
136
|
+
|
137
|
+
cell.labelBottom.text = ""
|
138
|
+
|
139
|
+
cell.viewBar.hidden = true
|
140
|
+
|
141
|
+
} else {
|
142
|
+
|
143
|
+
//open
|
144
|
+
|
145
|
+
cell.labelBottom.text = msgBottom[indexPath.row]
|
146
|
+
|
147
|
+
cell.viewBar.hidden = false
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
return cell
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
|
160
|
+
|
161
|
+
return UITableViewAutomaticDimension
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
|
168
|
+
|
169
|
+
{
|
170
|
+
|
171
|
+
return UITableViewAutomaticDimension
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
```
|
176
|
+
|
177
|
+
|
2
estimatedHeightForRowAtIndexPath
test
CHANGED
@@ -65,3 +65,25 @@
|
|
65
65
|
```
|
66
66
|
|
67
67
|
|
68
|
+
|
69
|
+
# estimatedHeightForRowAtIndexPath
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
同じ値にしたいのでheightForRowAtIndexPathを呼び出しています。
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
```swift
|
78
|
+
|
79
|
+
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
return self.tableView(tableView, heightForRowAtIndexPath: indexPath)
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
|
1
rowHeight
test
CHANGED
@@ -31,3 +31,37 @@
|
|
31
31
|
}
|
32
32
|
|
33
33
|
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
# セルの高さ
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
tableView.rowHeightを使うのではなく、下のようにしてセルの高さを保存しておいてもいいかと思います。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```swift
|
46
|
+
|
47
|
+
var rowHeight: CGFloat = 44.0
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
override func viewDidLayoutSubviews() {
|
52
|
+
|
53
|
+
super.viewDidLayoutSubviews()
|
54
|
+
|
55
|
+
if let cell = tableView.dequeueReusableCellWithIdentifier("Cell") {
|
56
|
+
|
57
|
+
rowHeight = CGRectGetHeight(cell.frame)
|
58
|
+
|
59
|
+
print("rowHeight=", rowHeight)
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
|