代码基于: Swift 4.0
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "XXTestCell", for: indexPath) as! XXTestCell
// 防止引用循环
// 1. 重新获取一个局部cell
// cell.buttonCallBack = {
// let cell = tableView.cellForRow(at: indexPath) as? XXTestCell
// cell?.configureLabel(with: "110")
// }
// 2.不用重新获取,[weak cell]方式。以前没用过,用了之后发现很好用(推荐这种)
cell.buttonCallBack = { [weak cell] in
cell?.configureLabel(with: "110")
}
return cell
}
网友评论