我打電話給一個JSON並將數據保存在一個數組上,然後重新加載tableView,當我使用dequeueReusableCell
一切正常時,但是當我更改爲cellForRow
我每次遇到崩潰時都會崩潰細胞。究其原因即時通訊使用cellForRow是我需要的用戶點擊它後更改單元格的形象,但如果我使用dequeueReusableCell
我得到多種變化(因爲細胞總是重複使用)。cellForRow返回nil - swift 3
我在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'加入,您需要使用'dequeueReusableCell'和添加在你的問題重複使用的問題。 –
您應該在'cellForRowAt'中使用'dequeueReusableCell',並在其他地方使用'cellForRow'。 – kennytm