これはエラーです。私はこれが簡単な修正だと確信していますが、私はそれに少し問題があります。このスレッドを更新してコードを追加しました。"タイプ 'UITableViewCell'の値を 'UILabel'にキャストできませんでした。"
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return 5
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CheckListItem", for: indexPath)
let label = cell.viewWithTag(1000) as! UILabel
switch indexPath.row {
case 0:
label.text = "Walk the dog"
case 1:
label.text = "Brush my teeth"
case 2:
label.text = "Learn iOS development"
case 3:
label.text = "Soccer practice"
case 4:
label.text = "Eat ice cream"
default:
label.text = "Nothing"
}
return cell
}
ラベルまたはセルにタグを設定しましたか?また、本当にタグで作業するべきではありません。セルをサブクラス化し、セルサブクラスのラベルとプロパティの間にコンセントを設定します。 –
画像としてコードを投稿しないでください。関連コードをコピーしてテキストとして質問に貼り付けてください。それは、読んだり、参照するのが簡単になります。 – rmaddy
ありがとうございます。セルではなく、ラベルにタグを設定する必要がありました。 –