JSONを呼び出して配列にデータを保存した後、tableViewをリロードした後、dequeueReusableCell
を使用すると、すべてが機能しますが、cellForRow
に変更すると、設定するたびにクラッシュします細胞。 CellForRowを使用している理由は、ユーザーがクリックした後にセルの画像を変更する必要があることです。ただし、dequeueReusableCell
を使用すると、セルが常に再利用されるため、複数の変更があります。cellForRowはnil-swiftを返します。
私はlet cell = tableView.cellForRow(at: indexPath) as! TicketTableViewCell
でクラッシュしています。私はすでに検索を行ったが、何も助けなかった。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.cellForRow(at: indexPath) as! TicketTableViewCell
//let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TicketTableViewCell
cell.date.text = arrDate[indexPath.row].date
//Top Bottom Space.
let maskLayer = CAShapeLayer()
let bounds = cell.bounds
maskLayer.path = UIBezierPath(roundedRect: CGRect(x: 2, y: 2, width: bounds.width-4, height: bounds.height-4), cornerRadius: 2).cgPath
cell.layer.mask = maskLayer
return cell
}
明らかに、そのセルが 'indexPath'に追加されないので、あなたにはnilが与えられます。あなたは' dequeueReusableCell'を使う必要があります。あなたの質問で再利用の問題を追加する必要があります。 –
'cellForRowAt'では' dequeueReusableCell'を、別の場所では 'cellForRow'を使うべきです。 – kennytm