我有一个像这样的协议:
public protocol SubmitAgeDelegate : class {
func changeSubmitButtonBool()
}
问题是我想在泛型类中调用它。
open class GenericController<UICollectionViewCell,UICollectionReusableView> {
weak var submitAgeDelegate: SubmitAgeDelegate?
在 UITapGestureRecognizer 内
func tapGestureDidRecognize(_ gesture: UITapGestureRecognizer) {
if let myAgeDelegate = self.submitAgeDelegate {
print("inside delegate") //Never gets inside
myAgeDelegate.changeSubmitButtonBool()
}
}
不太清楚为什么它永远不会被调用?类似的方法也适用于使用 IBAction 函数的常规类。
在我的另一堂课上:
open class MyCell: ActionCell, SubmitAgeDelegate {
weak var submitAgeDelegate: SubmitAgeDelegate?
public override init(frame: CGRect) {
super.init(frame: frame)
submitAgeDelegate = self
initialize()
}
// Delegate
public func changeSubmitButtonBool(){
print("called ")
}
你永远不会设置submitAgeDelegate
of the GenericController
。您的帐户中有同名成员MyCell
类没有帮助。
您需要获得您的参考GenericController
为了设置其代表;没有办法解决这个问题。 (这与泛型没有任何关系;对于非泛型类也是如此。)因为看起来您正在将它用作UICollectionViewCell
,您可以使用您在中所做的参考tableView:cellForRowAtIndexPath:
或类似的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)