質問編集履歴

4

コードの変更

2018/03/13 06:28

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -224,32 +224,24 @@
224
224
 
225
225
  ```swift
226
226
 
227
- let item = ["name"]
228
-
229
-
230
-
231
227
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
232
228
 
233
229
  let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
234
230
 
235
- //let item = add
231
+ let name = add
236
-
237
- let label = cell.textLabel as! UILabel
232
+
238
-
239
- add.text = String(indexPath.row + 1)
240
-
241
- cell.textLabel?.text = item[indexPath.row]
233
+ cell.textLabel?.text = name[indexPath.row]
242
234
 
243
235
  return cell
244
236
 
245
237
  }
246
238
 
239
+ }
240
+
247
241
 
248
242
 
249
243
  ```
250
244
 
251
- このようにするとlabelは表示はされるのですがcell内にlabelが挿入されません。
252
-
253
245
 
254
246
 
255
247
  ![イメージ説明](45d68e78309d231e86a5207a42576411.png)
@@ -257,3 +249,7 @@
257
249
 
258
250
 
259
251
  初心者なので具体的なコードを教えて頂きたいです。
252
+
253
+ cell.textLabel?.text = name[indexPath.row]←ようにすると以下のエラーがおきます。
254
+
255
+ type 'UILabel' has no subscript members

3

コードの編集、写真の追加

2018/03/13 06:28

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -224,6 +224,10 @@
224
224
 
225
225
  ```swift
226
226
 
227
+ let item = ["name"]
228
+
229
+
230
+
227
231
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
228
232
 
229
233
  let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
@@ -234,16 +238,22 @@
234
238
 
235
239
  add.text = String(indexPath.row + 1)
236
240
 
237
- //cell.textLabel?.text = item[indexPath.row]
241
+ cell.textLabel?.text = item[indexPath.row]
238
242
 
239
243
  return cell
240
244
 
241
245
  }
242
246
 
247
+
248
+
243
249
  ```
244
250
 
245
251
  このようにするとlabelは表示はされるのですがcell内にlabelが挿入されません。
246
252
 
247
253
 
248
254
 
249
- ![イメージ説明](2470b678cedbec3e682b35de92b5ef2c.png)
255
+ ![イメージ説明](45d68e78309d231e86a5207a42576411.png)
256
+
257
+
258
+
259
+ 初心者なので具体的なコードを教えて頂きたいです。

2

コードの編集と画像の追加

2018/03/12 15:33

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -219,3 +219,31 @@
219
219
  cellForRowAtの中のコードの書き方がtableViewにただ文字を挿入する方法は分かるのですがlabelをtableViewに追加する方法を分からなくて困っています。
220
220
 
221
221
  あと引数はこの三つだけいいのかも分からなくて困っています。
222
+
223
+
224
+
225
+ ```swift
226
+
227
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
228
+
229
+ let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
230
+
231
+ //let item = add
232
+
233
+ let label = cell.textLabel as! UILabel
234
+
235
+ add.text = String(indexPath.row + 1)
236
+
237
+ //cell.textLabel?.text = item[indexPath.row]
238
+
239
+ return cell
240
+
241
+ }
242
+
243
+ ```
244
+
245
+ このようにするとlabelは表示はされるのですがcell内にlabelが挿入されません。
246
+
247
+
248
+
249
+ ![イメージ説明](2470b678cedbec3e682b35de92b5ef2c.png)

1

コードの編集

2018/03/11 03:54

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -152,11 +152,11 @@
152
152
 
153
153
 
154
154
 
155
- /*func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
155
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
156
156
 
157
157
  return add
158
158
 
159
- }*/
159
+ }
160
160
 
161
161
 
162
162