我有一个UIViewController,其中有一个UICollectionView,里面我有一个ListSectionController控制 a 的类,UICollectionViewCell在那个单元格里面我有一个UIView子类。
当按下按钮时,我需要从UIViewController. 目前我有一系列委托方法,因为它可以像这样回到视图控制器:
class MyView {
// delegate is the cell that the view is contained in
@IBAction func buttonPress() {
delegate?.myDelegateMethod()
}
}
extension MyCell : MyViewDelegate {
// The delegate is the section controller
func myDelegateMethod() {
delegate?.myDelegateMethod()
}
}
... etc
这似乎有很多代码重复,有点浪费空间。我该如何改进呢?