【发布时间】:2020-02-26 13:44:24
【问题描述】:
我有一个表格视图,用于配置一个单元格(来自 VC),
cell.model = dataSource[indexpath.row]
在 cell.model 的 didSet 中,我正在初始化单元格内容。 Cell 有 3 个按钮,点击它,我通过 CellDelegate 通知 VC
protocol CellDelegate {
func didTapButton1(model: Model)
func didTapButton2(model: Model)
func didTapButton3(model: Model)
}
我的担心:- 我不想在这里传递模型(因为它已经与单元相关联 - 不知何故需要从单元中获取模型) 我想在没有参数的情况下调用 didTapButton() 。然后在VC里面,
extension VC: CellDelegate {
//I need to fetch the model associated with the cell.
func didTapButton1() { }
func didTapButton2() { }
func didTapButton3() { }
}
我可以使用闭包来实现这一点,但这里不是首选。 任何帮助将不胜感激。*
【问题讨论】:
-
为什么不想传递模型参数?委托中只有一个函数 -
didTapButton(model:buttonNumber:)怎么样?
标签: swift generics delegates delegation redundancy