質問編集履歴

3

ソースの更新

2019/12/02 01:20

投稿

entaro12345
entaro12345

スコア75

test CHANGED
File without changes
test CHANGED
@@ -8,11 +8,13 @@
8
8
 
9
9
  中身はコードだけで実装したいです。
10
10
 
11
+
12
+
11
- しかし、TableViewCellのカスタムクラス作成しようとし際にどうてもOutlet接続が必要になりました。
13
+ takabosoft様からご回答だきコードは修正エラーは解消しました。
12
-
14
+
13
- ルに文言と画像を入れたセルを作成ためです。
15
+ が、ットるつもりなのですが、テキストも画像も表示されません
14
-
16
+
15
- cellへの値セット時でエラーとなってます。
17
+ ご協力お願いいたします。
16
18
 
17
19
 
18
20
 
@@ -30,25 +32,7 @@
30
32
 
31
33
 
32
34
 
33
- ```
34
-
35
- Could not cast value of type 'UITableViewCell' to 'アプリ名.CustomTableViewCell'
36
-
37
-
38
-
39
- 上記は、回答いただいた内容で解消されました
35
+ 何も表示されません
40
-
41
-
42
-
43
- cell.id.text = testData[indexPath.row].id
44
-
45
- 上記実行時に、エラーとなってしまいます。
46
-
47
- cellの値を見ると「CustomTableViewCell」のクラスをうまく取得できていなように見えます。
48
-
49
-
50
-
51
- ```
52
36
 
53
37
 
54
38
 
@@ -66,9 +50,9 @@
66
50
 
67
51
 
68
52
 
69
- var id : UILabel!
53
+ var id = UILabel()
70
-
54
+
71
- var icon: UIImageView!
55
+ var icon = UIImageView()
72
56
 
73
57
 
74
58
 
@@ -222,8 +206,12 @@
222
206
 
223
207
  let cell:CustomTableViewCell = tableView.dequeueReusableCell(withIdentifier: "CustomTableViewCell", for: indexPath) as! CustomTableViewCell
224
208
 
209
+ cell.id.frame = CGRect(x:0, y:0, width: 150, height:30)
210
+
225
211
  cell.id.text = testData[indexPath.row].id
226
212
 
213
+ cell.imgName.image = UIImage(named: testData[indexPath.row].imgName
214
+
227
215
  return cell
228
216
 
229
217
  }

2

コードの追記

2019/12/02 01:19

投稿

entaro12345
entaro12345

スコア75

test CHANGED
File without changes
test CHANGED
@@ -146,14 +146,82 @@
146
146
 
147
147
 
148
148
 
149
+ override func viewDidLoad() {
150
+
151
+ super.viewDidLoad()
152
+
153
+
154
+
155
+ // 画面サイズを取得する
156
+
157
+ let iWidthScreen = self.view.frame.size.width
158
+
159
+ let iHeightScreen = self.view.frame.size.height
160
+
161
+
162
+
163
+ // タイトル
164
+
165
+ let lblTitle = UILabel()
166
+
167
+ lblTitle.frame = CGRect(x: 0, y: 45, width: iWidthScreen, height: 20)
168
+
169
+ lblTitle.text = "タイトル"
170
+
171
+ lblTitle.textAlignment = NSTextAlignment.center
172
+
173
+ self.view.addSubview(lblTitle)
174
+
175
+
176
+
177
+ // ID一覧
178
+
179
+ let tableView = UITableView()
180
+
181
+ tableView.frame = CGRect(x: 5, y: iHeightScreen * 0.15, width: iWidthScreen - 10, height: iHeightScreen * 0.7)
182
+
183
+ tableView.delegate = self
184
+
185
+ tableView.dataSource = self
186
+
187
+ self.view.addSubview(tableView)
188
+
189
+
190
+
191
+ // 完了ボタン
192
+
193
+ let btnConplete = UIButton()
194
+
195
+ btnConplete.frame = CGRect(x: iWidthScreen * 0.1, y: iHeightScreen * 0.9, width: iWidthScreen * 0.8, height: 50)
196
+
197
+ btnConplete.setTitle("ボタン1")
198
+
199
+ btnConplete.layer.cornerRadius = 12
200
+
201
+ btnConplete.addTarget(self, action: #selector(btnNext_touched), for: .touchUpInside)
202
+
203
+ self.view.addSubview(btnConplete)
204
+
205
+   }
206
+
207
+
208
+
209
+ // TableView表示個数
210
+
211
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
212
+
213
+ return testData.count
214
+
215
+ }
216
+
217
+
218
+
149
- // セルに値をセット
219
+   // セルに値をセット
150
-
220
+
151
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
221
+   func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
152
222
 
153
223
  let cell:CustomTableViewCell = tableView.dequeueReusableCell(withIdentifier: "CustomTableViewCell", for: indexPath) as! CustomTableViewCell
154
224
 
155
-
156
-
157
225
  cell.id.text = testData[indexPath.row].id
158
226
 
159
227
  return cell

1

エラー内容の変更

2019/11/22 08:50

投稿

entaro12345
entaro12345

スコア75

test CHANGED
File without changes
test CHANGED
@@ -8,9 +8,11 @@
8
8
 
9
9
  中身はコードだけで実装したいです。
10
10
 
11
- しかし、TableViewのカスタムクラスを作成しようとした際に、どうしてもOutlet接続が必要になりました。
11
+ しかし、TableViewCellのカスタムクラスを作成しようとした際に、どうしてもOutlet接続が必要になりました。
12
12
 
13
13
  各セルに文言と画像を入れたセルを作成したいためです。
14
+
15
+ cellへの値セット時でエラーとなってます。
14
16
 
15
17
 
16
18
 
@@ -31,6 +33,20 @@
31
33
  ```
32
34
 
33
35
  Could not cast value of type 'UITableViewCell' to 'アプリ名.CustomTableViewCell'
36
+
37
+
38
+
39
+ 上記は、回答いただいた内容で解消されました。
40
+
41
+
42
+
43
+ cell.id.text = testData[indexPath.row].id
44
+
45
+ 上記実行時に、エラーとなってしまいます。
46
+
47
+ cellの値を見ると「CustomTableViewCell」のクラスをうまく取得できていなように見えます。
48
+
49
+
34
50
 
35
51
  ```
36
52
 
@@ -138,7 +154,7 @@
138
154
 
139
155
 
140
156
 
141
- cell.setCell(testData[indexPath.row])
157
+ cell.id.text = testData[indexPath.row].id
142
158
 
143
159
  return cell
144
160