teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

実行箇所の追加

2018/10/23 02:17

投稿

sw07
sw07

スコア22

title CHANGED
File without changes
body CHANGED
@@ -39,7 +39,7 @@
39
39
 
40
40
  ### 該当のソースコード
41
41
  ```
42
- ▼Label側(Viewの中にLabelを配置) Labelはstoryboard上でLines=0としております
42
+ ▼Label側(Viewの中にLabelを配置) Labelはstoryboard上でLines=0としております
43
43
  // View include Label
44
44
  labelBaseView.translatesAutoresizingMaskIntoConstraints = false
45
45
  NSLayoutConstraint.activate([
@@ -76,6 +76,28 @@
76
76
  textView.trailingAnchor.constraint(equalTo: textBaseView.trailingAnchor)
77
77
  ])
78
78
 
79
+ ▼実行箇所
80
+
81
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
82
+ let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! sampleTableViewCell
83
+ cell.labelName.text = "1234567890"
84
+ ★ここでLabel側の制約処理を実行しています
85
+ return cell
86
+ }
87
+
88
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
89
+ sampleTableView.estimatedRowHeight = 150
90
+ return UITableViewAutomaticDimension
91
+ }
92
+
93
+ func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
94
+ tableView.beginUpdates()
95
+ ★ここでTextView側の制約処理を実行しています
96
+ tableView.estimatedRowHeight = 150
97
+ tableView.rowHeight = UITableViewAutomaticDimension
98
+ tableView.endUpdates()
99
+ }
100
+
79
101
  ```
80
102
 
81
103
  ### 試したこと

2

誤記の修正

2018/10/23 02:17

投稿

sw07
sw07

スコア22

title CHANGED
File without changes
body CHANGED
@@ -70,10 +70,10 @@
70
70
  // TextView
71
71
  textView.translatesAutoresizingMaskIntoConstraints = false
72
72
  NSLayoutConstraint.activate([
73
- textView.topAnchor.constraint(equalTo: inputBaseView.topAnchor),
73
+ textView.topAnchor.constraint(equalTo: textBaseView.topAnchor),
74
- textView.bottomAnchor.constraint(equalTo: inputBaseView.bottomAnchor),
74
+ textView.bottomAnchor.constraint(equalTo: textBaseView.bottomAnchor),
75
- textView.leadingAnchor.constraint(equalTo: inputBaseView.leadingAnchor),
75
+ textView.leadingAnchor.constraint(equalTo: textBaseView.leadingAnchor),
76
- textView.trailingAnchor.constraint(equalTo: inputBaseView.trailingAnchor)
76
+ textView.trailingAnchor.constraint(equalTo: textBaseView.trailingAnchor)
77
77
  ])
78
78
 
79
79
  ```

1

該当のソースコードに制約のコードを追加

2018/10/23 01:55

投稿

sw07
sw07

スコア22

title CHANGED
File without changes
body CHANGED
@@ -38,7 +38,46 @@
38
38
 
39
39
 
40
40
  ### 該当のソースコード
41
+ ```
42
+ ▼Label側(Viewの中にLabelを配置) Labelはstoryboard上でLines=0としております
43
+ // View include Label
44
+ labelBaseView.translatesAutoresizingMaskIntoConstraints = false
45
+ NSLayoutConstraint.activate([
46
+ labelBaseView.widthAnchor.constraint(equalToConstant: 400.0),
47
+ labelBaseView.topAnchor.constraint(equalTo: cell.topAnchor, constant: 5.0),
48
+ labelBaseView.leadingAnchor.constraint(equalTo: cell.leadingAnchor, constant: 10.0),
49
+ labelBaseView.bottomAnchor.constraint(equalTo: cell.bottomAnchor, constant: 0.0)
50
+ ])
51
+ // Label
52
+ labelName.translatesAutoresizingMaskIntoConstraints = false
53
+ NSLayoutConstraint.activate([
54
+ labelName.topAnchor.constraint(equalTo: labelBaseView.topAnchor, constant: 0.0),
55
+ labelName.leadingAnchor.constraint(equalTo: labelBaseView.leadingAnchor, constant: 0.0),
56
+ labelName.trailingAnchor.constraint(equalTo: labelBaseView.trailingAnchor, constant: 0.0),
57
+ labelName.bottomAnchor.constraint(equalTo: labelBaseView.bottomAnchor, constant: 0.0)
58
+ ])
41
59
 
60
+ ▼TextView側(Viewの中にTextViewを配置)
61
+ // View include TextView
62
+ textBaseView.translatesAutoresizingMaskIntoConstraints = false
63
+ textBaseView.heightAnchor.constraint(equalToConstant: 300.0).isActive = true
64
+ textBaseView.topAnchor.constraint(equalTo: cell.topAnchor, constant: 10.0).isActive = true
65
+ textBaseView.leadingAnchor.constraint(equalTo: labelBaseView.trailingAnchor, constant: 8.0).isActive = true
66
+ textBaseView.trailingAnchor.constraint(equalTo: cell.trailingAnchor, constant: -10.0).isActive = true
67
+ if labelHeight < 300.0 {
68
+ inputBaseView.bottomAnchor.constraint(equalTo: cell.bottomAnchor, constant: -10.0).isActive = true
69
+ }
70
+ // TextView
71
+ textView.translatesAutoresizingMaskIntoConstraints = false
72
+ NSLayoutConstraint.activate([
73
+ textView.topAnchor.constraint(equalTo: inputBaseView.topAnchor),
74
+ textView.bottomAnchor.constraint(equalTo: inputBaseView.bottomAnchor),
75
+ textView.leadingAnchor.constraint(equalTo: inputBaseView.leadingAnchor),
76
+ textView.trailingAnchor.constraint(equalTo: inputBaseView.trailingAnchor)
77
+ ])
78
+
79
+ ```
80
+
42
81
  ### 試したこと
43
82
 
44
83
  ### 補足情報(FW/ツールのバージョンなど)