【发布时间】:2021-01-19 01:41:04
【问题描述】:
为了避免保留循环,是否有必要在 UITableViewCell 按钮操作中使用 [weak self] in?示例:
在 ViewController 的cellForRow
cell.buttonAction = { (cell) [weak self] in
self.someFunction()
}
在 TableViewCell 类中
var buttonAction: ((UITableViewCell) -> Void)?
@IBAction func buttonPressed(_ sender: Any) {
buttonAction?(self)
}
【问题讨论】:
-
为什么不在内存图调试器中看一下,让你自己看看呢?这是一个很好的学习机会
标签: ios swift uitableview uibutton retain-cycle