回答編集履歴
4
。
answer
CHANGED
|
@@ -55,6 +55,8 @@
|
|
|
55
55
|
* viewBarは下線(区切り線)のUIView
|
|
56
56
|
* toggleは配列にしています
|
|
57
57
|
|
|
58
|
+
となっています。
|
|
59
|
+
|
|
58
60
|
```swift
|
|
59
61
|
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
|
60
62
|
|
3
なんやかんやで。
answer
CHANGED
|
@@ -42,3 +42,47 @@
|
|
|
42
42
|
return self.tableView(tableView, heightForRowAtIndexPath: indexPath)
|
|
43
43
|
}
|
|
44
44
|
```
|
|
45
|
+
|
|
46
|
+
# 色々と試した挙句
|
|
47
|
+
|
|
48
|
+
これがシンプルで良いという結論に。高さはあくまで**おまかせ**で中身を変更します。
|
|
49
|
+
今のままだと下のマージンが広くなってしまいますが、気になるようならマージンの制約値を変えてやればいいと思います。(たぶん)
|
|
50
|
+
|
|
51
|
+
勝手に色々と追加していますが、
|
|
52
|
+
|
|
53
|
+
* labelTop,labelBottomは、それぞれ上ラベル、下ラベル
|
|
54
|
+
* msgTop,msgBottomは、それぞれ上メッセージ、下メッセージ
|
|
55
|
+
* viewBarは下線(区切り線)のUIView
|
|
56
|
+
* toggleは配列にしています
|
|
57
|
+
|
|
58
|
+
```swift
|
|
59
|
+
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
|
60
|
+
|
|
61
|
+
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCell
|
|
62
|
+
|
|
63
|
+
//上は常に全文表示
|
|
64
|
+
cell.labelTop.text = msgTop[indexPath.row]
|
|
65
|
+
|
|
66
|
+
//線から下は開いているときだけ
|
|
67
|
+
if toggle[indexPath.row] {
|
|
68
|
+
//close
|
|
69
|
+
cell.labelBottom.text = ""
|
|
70
|
+
cell.viewBar.hidden = true
|
|
71
|
+
} else {
|
|
72
|
+
//open
|
|
73
|
+
cell.labelBottom.text = msgBottom[indexPath.row]
|
|
74
|
+
cell.viewBar.hidden = false
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return cell
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
|
|
81
|
+
return UITableViewAutomaticDimension
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
|
|
85
|
+
{
|
|
86
|
+
return UITableViewAutomaticDimension
|
|
87
|
+
}
|
|
88
|
+
```
|
2
estimatedHeightForRowAtIndexPath
answer
CHANGED
|
@@ -31,3 +31,14 @@
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
|
+
|
|
35
|
+
# estimatedHeightForRowAtIndexPath
|
|
36
|
+
|
|
37
|
+
同じ値にしたいのでheightForRowAtIndexPathを呼び出しています。
|
|
38
|
+
|
|
39
|
+
```swift
|
|
40
|
+
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
|
|
41
|
+
{
|
|
42
|
+
return self.tableView(tableView, heightForRowAtIndexPath: indexPath)
|
|
43
|
+
}
|
|
44
|
+
```
|
1
rowHeight
answer
CHANGED
|
@@ -14,4 +14,20 @@
|
|
|
14
14
|
return tableView.rowHeight //※デフォルトサイズを返す
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
```
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
# セルの高さ
|
|
20
|
+
|
|
21
|
+
tableView.rowHeightを使うのではなく、下のようにしてセルの高さを保存しておいてもいいかと思います。
|
|
22
|
+
|
|
23
|
+
```swift
|
|
24
|
+
var rowHeight: CGFloat = 44.0
|
|
25
|
+
|
|
26
|
+
override func viewDidLayoutSubviews() {
|
|
27
|
+
super.viewDidLayoutSubviews()
|
|
28
|
+
if let cell = tableView.dequeueReusableCellWithIdentifier("Cell") {
|
|
29
|
+
rowHeight = CGRectGetHeight(cell.frame)
|
|
30
|
+
print("rowHeight=", rowHeight)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|