我打电话给一个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